MEF:我应该在哪里把CompositionContainer中? [英] MEF: Where should I put the CompositionContainer?

查看:253
本文介绍了MEF:我应该在哪里把CompositionContainer中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用温莎IOC容器为我的基于Web的应用,解决了数据访问层的实现应用程序应该使用我一直是。

I have been using the Windsor IoC Container for my web-based application, to resolve the data access layer implementation the application should use.

Web应用程序的用户界面将包括页面,每个页面由小单位称为portlet的。 (他们的概念有点类似部件。)这些所谓的portlet是基本的Web控件,可以在运行时配置的每一页invidually。

The web application's UI will consist of pages, and each page consists of small units called portlets. (Their concept is somewhat similar to widgets.) These so-called portlets are basically web controls and can be configured in runtime for every page invidually.

应用程序将随其中的一些内置的,但我想能很容易地扩展它。

The application will ship with some of these built-in, but I would like to enable extending it easily.

我想通了,这种机制正是MEF是专为。所以,我决定实施该系统,它使用MEF发现portlet的这样一种方式。然后,我意识到,自己还可以做我现在使用的温莎,所以我决定放弃温莎赞成MEF的。

I figured out that this mechanism is exactly what MEF is built for. So I decided to implement the system in such a way that it discovers portlets using MEF. Then, I realized that it can also do what I currently use Windsor for, so I decided to ditch Windsor in favor of MEF.

很显然,我将不得不使用DirectoryCatalog,它扫描的应用程序的bin文件夹的.dll文件,并返回我需要的一切。

Obviously, I will have to use the DirectoryCatalog, which scans for the .dlls in the app's bin folder and returns everything I need.

我看了一些教程,范例,以及关于MEF在StackOverflow的所有问题,以及。我想,要使用MEF最简单的方法是,通过它格伦座在他的教程中提到的PartInitializer,但我意识到,这是不是在MEF。其实,这是在code,我从$下载C $ CPLEX,但在一个单独的程序,只有在来源,而不是二进制形式。 (这是否意味着它不是MEF的一部分吗?或者有什么意义地把它给一个单独的项目?) 然后,我意识到,这是Silverlight的,所以它并没有真正帮助我。 (或者我应该只是编译针对.NET 3.5,或者将其包含在我的项目,我好去?)

I read some tutorials, examples, and all questions regarding MEF in StackOverflow, as well. I figured that the easiest way to use MEF is through the PartInitializer which Glenn Block mentioned in his tutorials, but I realized that it is not in MEF. Actually, it is in the code I downloaded from CodePlex, but in a separate assembly, and only in source, not in binary form. (Does this mean that it isn't a part of MEF? Or what's the point in putting it to a separate project?) Then, I realized that it is for Silverlight, so it doesn't really help me. (Or should I just compile that against .NET 3.5, or include it in my project, and I'm good to go?)

所以现在我有一个问题,如下:?我应该在哪里把CompositionContainer中在我的应用程序

So now I have a problem which is the following: where should I put the CompositionContainer in my application?

还有一件事我要考虑:我应该在应用程序的生命周期只用一个CompositionContainer中,或我最好创建一个容器,每一次当我需要它

There is another thing I would like to consider: should I use only one CompositionContainer in the lifetime of the app, or I'm better off creating a container for every time when I need it?

推荐答案

好的问题。

在一般约在何处放置容器,我建议以下职位方面的问题:<一href="http://blogs.msdn.com/nblumhardt/archive/tags/Container+Managed+Application+Design/default.aspx">http://blogs.msdn.com/nblumhardt/archive/tags/Container+Managed+Application+Design/default.aspx

In general in terms of questions about where to put the container, I recommend the following posts: http://blogs.msdn.com/nblumhardt/archive/tags/Container+Managed+Application+Design/default.aspx

在MEF在网络上的,基于Web的应用程序是因为请求/响应性和可扩展性的担忧有一些技巧性。用于网络你可能会希望有每个请求的层次结构的容器,一个根一个用于该共享的应用,以及儿童contianers。子容器应生活和请求,以节约资源死去。共享容器包含了所有呼叫者的共享服务。

In of MEF on the web, web-based apps are a bit tricker because of the request / response nature and scalability concerns. For web you would likely want to have a hierarchy of containers, one root one for the application which is shared, as well as child contianers per-request. The child containers should live and die with the request in order to conserve resources. The shared container contains services that are shared by all callers.

您可以看看这些文章更深入地了解如何做到这一点:

You might check out these articles for more insight into how to do this:

<一个href="http://blogs.msdn.com/hammett/archive/2009/04/23/mef-and-asp-net-mvc-sample.aspx">http://blogs.msdn.com/hammett/archive/2009/04/23/mef-and-asp-net-mvc-sample.aspx <一href="http://blogs.msdn.com/hammett/archive/2009/07/15/mef-and-asp-net-mvc-sample-updated.aspx">http://blogs.msdn.com/hammett/archive/2009/07/15/mef-and-asp-net-mvc-sample-updated.aspx <一href="http://mef.$c$cplex.com/wikipage?title=Parts%20Lifetime&referringTitle=Guide">http://mef.$c$cplex.com/wikipage?title=Parts%20Lifetime&referringTitle=Guide

据PartInitializer,我会避免使用类似的东西,除非你不得不这样做。 ASP.NET提供了足够的钩子通过HTTP处理程序,模块和这样的管道自动让撰写的创作。

As far as PartInitializer, I would avoid using something like it unless you have to. ASP.NET provides sufficient hooks in the pipeline through HTTP Handlers, modules and such to let automatically compose on creation.

我会看到使用PI在网络上唯一的地方将可能是一个自定义用户控件中。 PI船舶为Silverlight 4中的一部分,并没有针对.NET 4.0中可用。我创建了一个可用的版本.NET 4.0,你可以在这里找到:<一href="http://cid-f8b2fd72406fb218.skydrive.live.com/self.aspx/blog/Composition.Initialization.Desktop.zip">http://cid-f8b2fd72406fb218.skydrive.live.com/self.aspx/blog/Composition.Initialization.Desktop.zip

The only place i would see using PI on the web would be possibly within a custom user control. PI ships as part of Silverlight 4 and is not available in the box for .NET 4.0. I have created a usable version for .NET 4.0 which you can find here: http://cid-f8b2fd72406fb218.skydrive.live.com/self.aspx/blog/Composition.Initialization.Desktop.zip

HTH 格伦

这篇关于MEF:我应该在哪里把CompositionContainer中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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