是否应该使用托管扩展性框架来使用外部插件?
我想我得到了 MEF 模型。但我很难确定它是否适合我想做的事情。
我有一个应用程序,它将调用第三方插件来进行一些视频处理。该插件可以是 FFMPEG.exe 或 x264.exe,没关系。调用插件的过程是通过 ProcessStartInfo (基本上通过命令行)并传递一堆参数。例如
ffmpeg.exe -in "c:\vid.avi" -out "c:\vid.avi" -Xheight 100 -Xwidth 100
or
x264.exe -in "c:\vid.avi" -out "c:\vid.avi" -Yheight 100 -Ywidth 100
,每个插件都有自己的参数集,所以使用 MEF 是否合适,这样无论使用哪个插件,界面都是相同的(通过公共合同)?如果是这样,我必须为实现合同的每个插件编写一个包装类吗?
这是使用 MEF 的正确方法吗?一方面,我试图通过允许客户选择他们的插件来使我的应用程序可扩展。但我真的不确定 MEF 是否太过杀伤力,简单地使用配置文件来存储命令是更好的方法吗?
I think i get the MEF model. But I'm having a hard time seeing if it fit's with what I'm trying to do.
I have an app which will call out to third party plugins to do some video processing. The plugin can be FFMPEG.exe or x264.exe, doesn't matter. The process of calling the plugins is via the ProcessStartInfo (basically through the command line) and passing a bunch of parameters. e.g
ffmpeg.exe -in "c:\vid.avi" -out "c:\vid.avi" -Xheight 100 -Xwidth 100
or
x264.exe -in "c:\vid.avi" -out "c:\vid.avi" -Yheight 100 -Ywidth 100
Its a given that each plugin will have their own parameter sets so is it appropriate to use MEF so the interface will be the same no matter which plugin is used (alebit via a public contract)? If so, must I write a wrapper class for each plugin implementing the contract?
Is this the correct way to use MEF? On one hand I'm trying to make my app extensible by allowing customers to choose their plugins. But really I'm not sure if the MEF is overkill and simply using config files to store the command is a better approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您可以简单地使用配置文件,那么这将是更好的选择。它将允许添加或更改插件而无需重新编译。这也将为高级用户提供调整插件的机会。
If you have possibility to simply use config files then this will be preferable. It will allow to add or change plugins without recompiling. Also this will give opportunity to power user's to tweak plugins.
MEF 是为应用程序添加可扩展性的好方法。您只需在应用程序中定义一个接口,在外部组件中实现该接口,然后将 Export 属性添加到实现中。在应用程序中使用导入属性,您可以发现外部组件。有关详细信息,请参阅文档。如果您阅读本文,您将在不到 2 小时的时间内使用 MEF 运行一个应用程序。
回到主题:如果您只是使用不同的参数调用不同的应用程序,我不会选择 MEF,因为这有点矫枉过正。然而,使用 MEF 很有趣,如果您想尝试一下,您仍然可以将它用于您的应用程序,只是为了获得学习体验。
MEF is a great way to add extensibility to an application. You just have to define an interface in your application, implement that interface in the external component and add an Export attribute to the implementation. Using Import Attribute in your application you can discover the external component. See the documentation for details. If you read this, you have an application running using MEF in less than 2 hours.
Back to the topic: If you are only calling different applications with different arguments I wouldn't go for MEF because it would be a little overkill. However, MEF is fun to work with and if you like to experiment a little you could still use it for your application just for the learning experience.
听起来 MEF 对于你想要的东西来说可能有点过分了。您的插件已经是外部应用程序,并且您已经有一种方法来调用它们。编写包装器似乎需要更多工作!
Sounds like MEF is probably overkill for what you want. You're plugins are already external applications and you already have a way to call them. Writing the wrappers just seems like more work!