-
Notifications
You must be signed in to change notification settings - Fork 17
IoC Integration: Windsor
hazzik edited this page May 28, 2012
·
6 revisions
First off, install MvcExtensions.Windsor from nuget:
PM> Install-Package MvcExtensions.Windsor
Second off you need to inherit you MvcApplication class located in Global.asax.cs from MvcExtensions.Windsor.WindsorMvcApplication base class.
//Global.asax.cs
public class MvcApplication : MvcExtensions.Windsor.WindsorMvcApplication
{
}
Third you want to register controller handling by Castle.Windsor IoC container. For that just include RegisterControllers task into bootstrapper tasks executing sequence:
//Global.asax.cs
public class MvcApplication : MvcExtensions.Windsor.WindsorMvcApplication
{
public MvcApplication()
{
Bootstrapper.BootstrapperTasks
.Include<RegisterControllers>();
}
}
Next you should write some installers for IoC container (see http://docs.castleproject.org/Windsor.Installers.ashx). Place them somewhere in your application folder (for ex. into /Infrastructure) and it will be picked up automagically. Note that you shouldn`t install your controllers by that way, becouse it is already installed by framework.
public class AccountsInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component
.For<IAuthenticationService>()
.ImplementedBy<FormsAuthenticationService>()
.LifeStyle.Transient);
// ...
}
}