I know it’s possible to use DependencyResolver and register Castle Windsor with MVC but due to the issues described in https://stackoverflow.com/a/4889222/139392 we have stuck to the WindsorControllerFactory method of implementation on our MVC projects.
However it looks like the ApiControllers are using some other kind of factory as Castle Windsor is unable to inject the dependencies.
Has anyone figured out how to use Castle Windsor with ASP.NET Web API and MVC without using the DependencyResolver?
Thanks to Critiano’s post and some searching on-line I managed to get it to work here’s the code for anyone else having this issue. I’ve fgot it working with MVC3 and ASP.NET Web Api Beta but I think the same solution should work for MVC4.
Firstly I created a WindsorHttpControllerFactory as the ApiControllers use a different factory than the MVC ones.
The tricky part was registration it seems to involved registering a whole bunch of other stuff. This is what I ended up with.
I had to create my own implementation of an ILogger you could use a stub version like bellow.