castle PerRequestLifestyle nicht erkennen
eu in Castle / Windsor, bitte trage es mit mi
Ich benutze gerade das Framework System.Web.Mvc.Extensibility und in seinem Startcode registrierte er HttpContextBase wie folgt:
container.Register(Component.For<HttpContextBase>().LifeStyle.Transient.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
Was ich tun wollte, ist, das Verhalten und den Lebensstil von httpContextBase so zu ändern, dass es PerWebRequest ist.
so habe ich den Code folgendermaßen geändert:
container.Register(Component.For<HttpContextBase>().LifeStyle.PerWebRequest.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
Wenn ich das mache, erhalte ich jedoch den folgenden Fehler:
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
was ich getan habe unter<system.web>
und<system.webServer>
, aber ich erhalte immer noch den gleichen Fehler. Irgendwelche Hinweise?
Danke im Voraus
Aktualisiere
hinzugefügter Codeblock pro Anfrage
Im system.web.mvc.extensibility-Framework gibt es eine Klasse namens extendedMvcApplication, die von HttpApplication erbt, und in der Application_start-Methode wird BootStrapper.Execute () aufgerufen. Diese Implementierung dieser Methode sieht folgendermaßen aus:
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)
{
break;
}
shouldSkip = continuation == TaskContinuation.Skip;
}
}
Wie Sie sehen, durchläuft es eine Liste von IBootStrapperTask und versucht, sie auszuführen. Es kommt also vor, dass ich eine Aufgabe habe, die die Routen in meiner MVC-App registriert:
public class RegisterRoutes : RegisterRoutesBase
{
private HttpContextBase contextBase;
protected override TaskContinuation ExecuteCore(IServiceLocator serviceLocator)
{
contextBase = serviceLocator.GetInstance<HttpContextBase>();
return base.ExecuteCore(serviceLocator);
}
protected override void Register(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" });
XmlRouting.SetAppRoutes(routes, contextBase.Server.MapPath("~/Configuration/Routes.xml"));
}
}
Sie können sehen, dass ich ein httpcontextbase-Objekt abrufen (auflösen) muss, damit ich den Serverpfad einer XML-Datei abrufen kann.