简体   繁体   English

如何拥有一个可以在我的班级之间共享但不能在多个Web请求之间共享的Windsor IoC容器?

[英]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. 我正在构建一组类库,这些类库会生成基于Office Open xml的报告,并且正在使用静态的Windsor IoC容器。

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. 我的问题是,报告系统的一个可能的入口点是通过Web前端,这意味着报告系统静态IoC容器正在多个Web请求之间共享,这会导致报告系统尝试重新注册的每个新请求都出现异常温莎中已由先前请求注册的组件。

I dont want to move the registration into the web app global.asax as my reporting system will no longer be stand-alone. 我不想将注册移至网络应用程序global.asax中,因为我的报告系统将不再是独立的。

How can I have a Windsor IoC container that can be shared amongst my reporting classes but not shared across multiple web requests? 如何拥有一个可以在报告类之间共享但不能在多个Web请求之间共享的Windsor IoC容器?

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. 然后,在global.asax中,您只需安装安装程序,这很容易做到,而在即将推出的Windsor 2.5中,它实际上是两行代码。

Did you try the Lifestyle option for you components. 您是否尝试过为组件选择“生活方式”选项。 There is a PerWebRequestLifestyleManager and a PerWebRequestLifestyleModule option. 有一个PerWebRequestLifestyleManager和一个PerWebRequestLifestyleModule选项。 See here the documentation for lifestyles. 请参阅此处的生活方式文档。 And see here an example that uses the lifestyle options. 在此处查看使用生活方式选项的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以为所有Web应用程序共享一个类吗? - Can I have a class shared for all my web applications? 可以使用温莎城堡IOC容器注册代表吗? - Can delegates be registered with Castle Windsor IOC container? 如何命名温莎城堡中的容器? - How can I name a container in Castle Windsor? WCF服务:如何使用共享类? - WCF Service : how can I use shared classes? 如何在IIS实例中的所有应用程序/虚拟目录/版本之间共享Oracle连接池? - How can I get an Oracle connection pool shared across all applications/virtual directories/versions in my IIS instance? 如何使所有视图都可以访问共享的ProgressCircle控件? - How can I have a shared ProgressCircle control accessible to all views? 使用Unity IoC容器时如何注入属性? - How can I inject a property when using Unity IoC container? 如何告诉Web API / Castle Windsor路由引擎在我的存储库中使用其他数据库实例? - How can I tell the Web API / Castle Windsor routing engine to use a different database instance in my Repository? 如何在多个类中访问同一IoC容器(即Unity)? - How do I access the same IoC container (i.e. Unity) in multiple classes? Access 数据库应用程序可以跨桌面共享吗? - Can Access database applications be shared across desktops?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM