MEF(托管可扩展性框架)与 IoC/DI
MEF(托管扩展性框架)解决了哪些现有 IoC/DI 容器无法解决的问题?
What problems does MEF (Managed Extensibility Framework) solves that cannot be solved by existing IoC/DI containers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MEF的主要目的是可扩展性; 当应用程序的作者和插件(扩展)的作者不同并且除了已发布的接口之外彼此没有特定的了解时,充当“插件”框架( 合约)库。
MEF 解决的另一个问题空间与通常的 IoC 嫌疑人不同,并且 MEF 的优势之一是[扩展]发现。 它有很多可扩展的发现机制,可以对可以与扩展关联的元数据进行操作。 来自 MEF CodePlex 站点:
“MEF 允许使用附加元数据标记扩展,这有助于丰富的查询和过滤”
结合延迟加载标记扩展的能力,能够事先询问扩展元数据< /em> 加载打开了一系列有趣场景的大门,并大大启用了[插件]版本控制等功能。
MEF 还具有“合同适配器”,允许扩展“适应”或“转换”(从类型 > 到类型),并完全控制这些转换的细节。 合同适配器开辟了另一个与“发现”的含义和含义相关的创意前沿。
同样,MEF 的“意图”紧密关注匿名插件的可扩展性,这与其他 IoC 容器有很大区别。 因此,虽然 MEF 可用于组合,但这只是其功能相对于其他 IoC 的一个小交集,我怀疑我们未来将会看到很多乱伦的相互作用。
The principle purpose of MEF is extensibility; to serve as a 'plug-in' framework for when the author of the application and the author of the plug-in (extension) are different and have no particular knowledge of each other beyond a published interface (contract) library.
Another problem space MEF addresses that's different from the usual IoC suspects, and one of MEFs strengths, is [extension] discovery. It has a lot of, well, extensible discovery mechanisms that operate on metadata you can associate with extensions. From the MEF CodePlex site:
"MEF allows tagging extensions with additonal metadata which facilitates rich querying and filtering"
Combined with an ability to delay-load tagged extensions, being able to interrogate extension metadata prior to loading opens the door to a slew of interesting scenarios and substantially enables capabilities such as [plug-in] versioning.
MEF also has 'Contract Adapters' which allow extensions to be 'adapted' or 'transformed' (from type > to type) with complete control over the details of those transforms. Contract Adapters open up another creative front relative to just what 'discovery' means and entails.
Again, MEFs 'intent' is tightly focused on anonymous plug-in extensibility, something that very much differentiates it from other IoC containers. So while MEF can be used for composition, that's merely a small intersection of its capabilities relative to other IoCs, with which I suspect we'll be seeing a lot of incestuous interplay going forward.
IoC 容器专注于您知道的那些事情,即我知道我将在单元测试中使用一个记录器,并在我的应用程序中使用不同的记录器。 MEF 专注于那些你不关心的事情,我的系统中可能会出现 1 到 n 个记录器。
IoC containers focus on those things you know i.e. I know I will use one logger in a Unit Test, and a different Logger in my app. MEF focuses on those things you don't, there are 1 to n loggers that may appear in my system.
斯科特·汉塞尔曼和我在最近的汉塞尔会议纪要中更详细地讨论了这个话题。
http://www.hanselminites.com/default.aspx?showID=166
Scott Hanselman and I covered this topic in more detail in the recent hanselminutes.
http://www.hanselminutes.com/default.aspx?showID=166