Castle/Windsor新手,请耐心等待.
我目前正在使用框架System.Web.Mvc.Extensibility,并在其启动代码中,它注册了HttpContextBase,如下所示:
container.Register(Component.For<HttpContextBase>().LifeStyle.Transient.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
Run Code Online (Sandbox Code Playgroud)
我想要做的是改变行为并将httpContextBase的生活方式改为PerWebRequest.
所以我将代码更改为以下内容:
container.Register(Component.For<HttpContextBase>().LifeStyle.PerWebRequest.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,我收到以下错误:
System.Configuration.ConfigurationErrorsException: Looks like you forgot to
register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule
Add '<add name="PerRequestLifestyle"
type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel"
/>' to the <httpModules> section on your web.config
Run Code Online (Sandbox Code Playgroud)
这是我做下<system.web>和<system.webServer>,但是,我仍然得到同样的错误.任何提示?
提前致谢.
更新
每个请求添加了代码块
在system.web.mvc.extensibility框架中,有一个名为extendedMvcApplication的类,它继承自HttpApplication,在Application_start方法中,它调用BootStrapper.Execute().此方法的实现如下:
public void Execute()
{
bool shouldSkip = false;
foreach (IBootstrapperTask task in ServiceLocator.GetAllInstances<IBootstrapperTask>().OrderBy(task => task.Order))
{
if (shouldSkip)
{
shouldSkip = false;
continue;
}
TaskContinuation continuation = task.Execute(ServiceLocator);
if (continuation == TaskContinuation.Break) …Run Code Online (Sandbox Code Playgroud)