First of all you need to inherit you MvcApplication class located in Global.asax.cs from MvcExtensions.WindsorMvcApplication base class.

//Global.asax.cs
public class MvcApplication : MvcExtensions.WindsorMvcApplication
{
}

Second 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.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 <your mvc application>/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);
     }
}

Last edited Aug 19, 2011 at 11:30 PM by hazzik, version 4

Comments

No comments yet.