MEF与任何IoC [英] MEF vs. any IoC

查看:82
本文介绍了MEF与任何IoC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看Microsoft的Managed Extensibility Framework(MEF)和各种IoC容器(例如Unity),我看不到何时使用一种解决方案.更具体地说,似乎MEF可以处理大多数IoC类型模式,而像Unity这样的IoC容器则不是必需的.

Looking at Microsoft's Managed Extensibility Framework (MEF) and various IoC containers (such as Unity), I am failing to see when to use one type of solution over the other. More specifically, it seems like MEF handles most IoC type patterns and that an IoC container like Unity would not be as necessary.

理想情况下,我希望看到一个很好的用例,其中将使用IoC容器代替MEF或作为MEF的补充.

Ideally, I would like to see a good use case where an IoC container would be used instead of, or in addition to, MEF.

推荐答案

归根结底,主要区别是IoC容器通常对静态依赖项最有用(在编译时已知),而MEF通常对静态依赖项最有用.动态依赖项(仅在运行时已知).

When boiled down, the main difference is that IoC containers are generally most useful with static dependencies (known at compile-time), and MEF is generally most useful with dynamic dependencies (known only at run-time).

因此,它们都是合成引擎,但是每种模式的重点都大不相同.因此,由于MEF是围绕发现未知零件(而不是注册已知零件)进行优化的,因此设计决策会发生巨大变化.

As such, they are both composition engines, but the emphasis is very different for each pattern. Design decisions thus vary wildly, as MEF is optimized around discovery of unknown parts, rather than registrations of known parts.

这样想:如果您正在开发整个应用程序,则IoC容器可能是最好的.如果您正在编写可扩展性,例如第三方开发人员将扩展您的系统,那么MEF可能是最好的.

Think about it this way: if you are developing your entire application, an IoC container is probably best. If you are writing for extensibility, such that 3rd-party developers will be extending your system, MEF is probably best.

@Pavel Nikolov的答案中的文章也提供了一些很好的指导(由MEF的项目经理Glenn Block撰写).

Also, the article in @Pavel Nikolov's answer provides some great direction (it is written by Glenn Block, MEF's program manager).

这篇关于MEF与任何IoC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆