开发者

How can I have a Windsor IoC container that can be shared amongst my classes but not shared across multiple web requests?

I am building a set of class libraries that produce office open xml based reports and I am using a static Windsor IoC container.

My problem is that one possible entry point to the reporting system is via a web front end which means that the reporting systems static IoC Container is being shared amongst multiple web requests which causes exceptions as for each new request the reporting system is trying re-register components in Windsor that were already registered by an earlier request.

I dont want to move the registration into the 开发者_开发百科web app global.asax as my reporting system will no longer be stand-alone.

How can I have a Windsor IoC container that can be shared amongst my reporting classes but not shared across multiple web requests?


Don't recreate the container over and over again. Do create and setup it once per your application in global start point. You can still make your components self contained by encapsulating all registration in installers. Then in global.asax you'll only install the installers which is fairly easy to do and in upcoming Windsor 2.5 it's literally 2 lines of code.


Did you try the Lifestyle option for you components. There is a PerWebRequestLifestyleManager and a PerWebRequestLifestyleModule option. See here the documentation for lifestyles. And see here an example that uses the lifestyle options.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜