我在我的MVC 3.0应用程序中使用castle windsor 3.1.0.0进行依赖注入。Castle Windsor 3.1 PerWebRequestLifestyleModule配置
我的容器是设置提供的控制器是这样的:
container.Register(Classes.FromThisAssembly().BasedOn<IController>().LifestylePerWebRequest());
这似乎是工作,因为我看到每个请求创建一个新的控制器实例。然而根据documenation:http://docs.castleproject.org/Windsor.LifeStyles.ashx,我也必须把这个在我的web.config:
<httpModules>
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor"/>
</httpModules>
,我没有。如果这个模块缺失,Castle Windsor的行为是什么? (文档中说,为了使每个Web请求正常运行,您必须在您的Web配置中具有此功能)。
这确实是这样的情况:http://stackoverflow.com/questions/18576350/perwebrequest-and-transient-lifestyles –