When I load the application the container loads fine with all dependencies resolved as per screen shot on debug.
Yes, all your types are registered.
If you write var controller = container.Resolve<PersonController>();
in the Global.asax
you should get an instance of your controller.
Your implementation is valid for Asp.Net WebApi and it works for System.Web.Http.ApiController
s only.
Your code does not work properly because your PersonController
inherits System.Web.Mvc.Controller
and System.Web.Mvc.DefaultControllerFactory
is used. You can see it in the first picture.
You should write and inject your custom ControllerFactory in Global.asax
in order to create Asp.Net MVC controllers.
//Set the controller builder to use our custom controller factory
var controllerFactory = new WindsorControllerFactory(container);
ControllerBuilder.Current.SetControllerFactory(controllerFactory);
You can read more in this answer on another SO question.
Here is a default implementation of WindsorControllerFactory
:
/// <summary>
/// Controller factory the class is to be used to eliminate hard-coded dependencies
/// between controllers and other components
/// </summary>
public class ControllerFactory : DefaultControllerFactory
{
private readonly IWindsorContainer container;
public WindsorControllerFactory(IWindsorContainer container)
{
this.container = container;
}
public override void ReleaseController(IController controller)
{
container.Release(controller.GetType());
}
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
{
return (IController)container.Resolve(controllerType);
}
}