MEF: Where should I put the CompositionContainer?

前端 未结 1 1402
春和景丽
春和景丽 2021-02-04 06:46

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

The web application

相关标签:
1条回答
  • 2021-02-04 07:30

    Good questions.

    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

    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:

    http://blogs.msdn.com/hammett/archive/2009/04/23/mef-and-asp-net-mvc-sample.aspx http://blogs.msdn.com/hammett/archive/2009/07/15/mef-and-asp-net-mvc-sample-updated.aspx http://mef.codeplex.com/wikipage?title=Parts%20Lifetime&referringTitle=Guide

    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.

    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 Glenn

    0 讨论(0)
提交回复
热议问题