Autofac gets MVC Integration
Posted by Nicholas Blumhardt | December 13, 2007 20:37
Autofac now has ASP.NET MVC integration. This means that you can have Autofac create your controllers to handle web requests, cleanly wired up to their service dependencies from the container.
I had a look at the MVC Contrib project, hoping to add the Autofac integration there, but it seems like there is a bit of chaos going on there at the moment. Given that the idea of using an IoC container is to reduce coupling, I find it extremely amusing that the entire MVC Contrib project is currently implemented in a single assembly that references Windsor, Spring.NET and StructureMap! That's a lot of bulk to add for a class or two. I'm sure they'll sort it out soon though.
To take advantage of Autofac's dependency management and component disposal features, the integration creates an 'inner container' per web request. Getting an event handler for the HttpApplication.EndRequest event to fire reliably without requiring a handler in Global.asax.cs seems to necessitate an HTTP module implementation, so the integration currently requires you register it in Web.config.
If anyone out there knows how to:
- Reiliably handle EndRequest without an HTTP module, or
- Register an HTTP module programmatically
then please speak up! :)
Now that the new Entity Framework CTP is out, the real work can begin. The current plan is to provide an Autofac persistence service that can be used semi-transparently with either Microsoft's Linq to Entities or the Linq to NHibernate provider as the back-end. No doubt about it, that is going to be a challenge.
Comments
There are no comments on this article.
Disclaimer: These articles represent the opinions of the authors and may not match the official position of Ubik Systems Pty. Ltd. Confirmation should be sought on all matters involving professional advice.

Your Comment
Reset