Unity LifetimeManagers + ASP.NET

So recently I’ve really been looking into Unity and how to use it to handle IoC/DI for a future project of mine, I compeltely gave up on Web Client Software Factory (WCSF) something happened to that project where it just doesn’t work right anymore after having to deal with “Invalid owner for DynamicMethod” over and over again from ObjectBuilder(1.0 that’s in WCSF) I finally scrapped it and started looking at ways to use Unity to handle the MVP pattern instead.

This really had me scratching me on head on the implications of the page life cycle and correctly resolving instances, I’ve seen some examples around that go as far as creating HttpHandlers to intercept the BuildUp event to handle the injection which while I could go that route it definitely adds some complexity to the project. Which sadly I’ve learned especially when using new technology the code needs to be as simple as possible to avoid getting pushback from other developers but simple is good so I’d rather end up with a simple elegant solution vs a complex elegant solution.

Today I ran across a blog post (it’s a little old from May 08) regarding all of this Unity – lifetime management in a web application

I also did alot of referencing back and forth with the MSDN – Using Lifetime Managers

After doing some implemenation of all this I started to see why it makes sense to use the HttpModule to handle processing the build up. I used the HttpModule / Container wrapper extension method that Michael Puleio wrote on his blog Proof of Concept: a simple DI solution for ASP.NET WebForms.

Pretty soon I will be deploying a new solution to Assembla with links on here that will have an Unity driven DI model using the Model View Presenter (MVP) design pattern with a NHibernate back end (since LINQ-TO-SQL is on the death march) over the Microsoft Northwind db sample.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s