I am hoping someone can tell me what is wrong with my implementation of Castle Windsor. I have followed the tutorial Here. I have added a second installer that looks like this:
public class DataInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
//breakpoint on the line below is hit when the application starts.
container.Register(Component.For<IDataProvider>().ImplementedBy<MyDataProvider>());
}
}
My controller looks like this:
public IDataProvider Provider { get; set; }
public JsonResult Get()
{
//Provider is always null!!!
var data = Provider.Retrieve(a => true).ToArray();
//convert to JSON and return.
}
Why is my provider always null? My second installer is being hit when the application fires up, because it hits a breakpoint, but from what I can tell the rest of the application just ignores this.
Contents of my global.asax.cs
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
BootstrapContainer();
}
private static void BootstrapContainer()
{
container = new WindsorContainer().Install(FromAssembly.This());
var controllerFactory = new WindsorControllerFactory(container.Kernel);
ControllerBuilder.Current.SetControllerFactory(controllerFactory);
//container.Register(Component.For<IDataProvider>().ImplementedBy<MyDataProvider>().LifestyleSingleton());
}
I tried what the person did in this question, but that still resulted in the same problem. What am I missing here?
Edit: Someone asked if I registered the controller. The tutorial had me create the following class. I believe this would be registering the controllers?
public class ControllersInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Classes.FromThisAssembly().BasedOn<IController>().LifestyleTransient());
}
}