Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>Firstly I created a WindsorHttpControllerFactory as the ApiControllers use a different factory than the MVC ones.</p> <pre><code>public class WindsorHttpControllerFactory : IHttpControllerFactory { private readonly IKernel kernel; private readonly HttpConfiguration configuration; public WindsorHttpControllerFactory(IKernel kernel, HttpConfiguration configuration) { this.kernel = kernel; this.configuration = configuration; } public IHttpController CreateController(HttpControllerContext controllerContext, string controllerName) { if (controllerName == null) { throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", controllerContext.Request.RequestUri.AbsolutePath)); } var controller = kernel.Resolve&lt;IHttpController&gt;(controllerName); controllerContext.Controller = controller; controllerContext.ControllerDescriptor = new HttpControllerDescriptor(configuration, controllerName, controller.GetType()); return controllerContext.Controller; } public void ReleaseController(IHttpController controller) { kernel.ReleaseComponent(controller); } } </code></pre> <p>The tricky part was registration it seems to involved registering a whole bunch of other stuff. This is what I ended up with. </p> <pre><code>container.Register(Component.For&lt;IHttpControllerFactory&gt;().ImplementedBy&lt;WindsorHttpControllerFactory&gt;().LifeStyle.Singleton); container.Register(Component.For&lt;System.Web.Http.Common.ILogger&gt;().ImplementedBy&lt;MyLogger&gt;().LifeStyle.Singleton); container.Register(Component.For&lt;IFormatterSelector&gt;().ImplementedBy&lt;FormatterSelector&gt;().LifeStyle.Singleton); container.Register(Component.For&lt;IHttpControllerActivator&gt;().ImplementedBy&lt;DefaultHttpControllerActivator&gt;().LifeStyle.Transient); container.Register(Component.For&lt;IHttpActionSelector&gt;().ImplementedBy&lt;ApiControllerActionSelector&gt;().LifeStyle.Transient); container.Register(Component.For&lt;IActionValueBinder&gt;().ImplementedBy&lt;DefaultActionValueBinder&gt;().LifeStyle.Transient); container.Register(Component.For&lt;IHttpActionInvoker&gt;().ImplementedBy&lt;ApiControllerActionInvoker&gt;().LifeStyle.Transient); container.Register(Component.For&lt;System.Web.Http.Metadata.ModelMetadataProvider&gt;().ImplementedBy&lt;System.Web.Http.Metadata.Providers.CachedDataAnnotationsModelMetadataProvider&gt;().LifeStyle.Transient); container.Register(Component.For&lt;HttpConfiguration&gt;().Instance(configuration)); //Register all api controllers container.Register(AllTypes.FromAssembly(assemblyToRegister) .BasedOn&lt;IHttpController&gt;() .Configure(registration =&gt; registration.Named(registration.ServiceType.Name.ToLower().Replace("controller", "")).LifeStyle.Transient)); //Register WindsorHttpControllerFactory with Service resolver GlobalConfiguration.Configuration.ServiceResolver.SetService(typeof(IHttpControllerFactory), container.Resolve&lt;IHttpControllerFactory&gt;()); </code></pre> <p>I had to create my own implementation of an ILogger you could use a stub version like bellow.</p> <pre><code>public class MyLogger : System.Web.Http.Common.ILogger { public void LogException(string category, TraceLevel level, Exception exception) { // Do some logging here eg. you could use log4net } public void Log(string category, TraceLevel level, Func&lt;string&gt; messageCallback) { // Do some logging here eg. you could use log4net } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload