Use in Web App/Web Service App

Feb 19, 2008 at 9:51 AM
Just trying to get my head around Unity.

For Windows Forms the quickstart implies you need this...

Application.Run(container.Get<MainForm>());

If this is vital to ensuring that MainForm then uses dependency injection, how do I ensure the same for my web application (which clearly doesn't have a main form in this sense)
Feb 19, 2008 at 2:38 PM
In Asp.net MVC, you'll want a new ControllerFactory. David has great post regarding this here: http://davidhayden.com/blog/dave/archive/2008/02/14/ASPNETMVCFrameworkUnityDependencyInjectionContainerPartII.aspx

In regular WebForms, Unity supports to inject an already create object using BuildUp<T>.

Therefore, somewhere down the event chain (Page_Load being one), you could do:

container.BuildUp(this);