使用MEF作为IoC [英] Using MEF as an IoC

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

问题描述

阅读了一些资料后,例如: http://mikehadlow.blogspot.com /2008/09/managed-extensibility-framework-why.html

After reading some stuff such as this: http://mikehadlow.blogspot.com/2008/09/managed-extensibility-framework-why.html

我知道MEF有一些我在IoC中找不到的功能, MEF有一些IoC的东西,probaboly不像一些其他IoC系统可以提供的高级。

I understand that MEF has some featcures that I will not find in an IoC, and that MEF has some IoC stuff that is probaboly not as advanced as some other IoC systems can offer.

我需要MEF的东西。我还需要一个IoC框架或者我会对MEF有什么好的?

I need the MEF stuff. Do I also need an IoC framework or would I be fine with what MEF has?

Asher

推荐答案

取决于您的要求/现有代码。

Depends on your requirements/existing code.

如果您在IoC容器上构建了现有的代码基础结构,那么您实际上可以将它们与MEF组合。最近我一直在构建一个ASP.NET MVC + MEF框架,一些我的读者一直在问如何将Unity与我构建的MEF + MVC框架集成。由于一个名为通用服务定位器的项目,这真的很容易。

If you have an existing code infrastructure built on an IoC container, you can in fact combine these with MEF. Recently I've been building an ASP.NET MVC+MEF framework, and a couple of my readers have been asking how to integrate Unity with the MEF+MVC framework I have built. This turned out to be really easy, thanks to a project called the Common Services Locator.

CSL项目旨在提供对服务位置的抽象,因此我可以获取Unity的CSL提供商,使用自定义ExportProvider连接它,MEF自动开始撰写我的IoC驱动部分。

The CSL project is designed to provide an abstraction over service location, so I can grab a CSL provider for Unity, wire it up with a custom ExportProvider and MEF automatically starts composing my IoC-driven parts.

这是MEFs ExportProvider模型的优点之一,您可以轻松插入任何其他提供程序,从各种来源开始提取导出。

This is one of the benefits of MEFs ExportProvider model, you can easily plug in any additional providers to start pulling exports from a variety of sources.

上周我在博客中介绍了如何组合MEF + Unity 和MEF + Autofac作为另一个例子),虽然我的例子为ASP.NET MVC,但概念是一样的大多数其他实现相同。

Last week I blogged about combining MEF+Unity (and also MEF+Autofac as another exmaple), and although my examples are geared up for ASP.NET MVC, the concept is the same for most other implementations.

如果你有可能使用MEF构建新的选项,你可能会发现你不需要一个IoC容器,MEF可以处理属性注入,构造函数注入,部件生命周期管理和类型解析。

If you have the option of building something fresh using MEF, you'll probably find that you won't need an IoC container, MEF can handle property injection, constructor injection, part lifetime management, and type resolution.

如果您有任何问题,请告诉我们:)

Let me know if you have any questions :)

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

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