I have an ASP.NET MVC application which sets up an Autofac IOCContainer within the BeginRequest routine in Global.asax.
All is fine until one of my IIS7 UrlRwrite rules/conditions is met, e.g. lowercase url. I notice that as soon as I put an upper case letter within the url, so as the url rewrite rule is fired, the BeginRequest routine isn’t reached, but the EndRequest routine is.
The problem I have with this is that the IOCContainer is never set in this scenario, so when EndRequest is fired and I attempt to dispose of the web context/ioc container, it errors as there it was never set in the first place.
Why does the BeginRequest never get reached in the above scenario, and is there a common workaround for the IOC issue that arises because of it?
The
AutofacDependencyResolverthat is part of the Autofac MVC integration already creates a new lifetime scope at the start of each HTTP request and will dispose it when the HTTP request ends. You should not need to manage this yourself. Do you have this problem when you use the DependencyResolver mechanism?You can find out more about the MVC integration on the Autofac wiki.
http://code.google.com/p/autofac/wiki/Mvc3Integration