Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:21:50+00:00 2026-05-31T18:21:50+00:00

I know it’s possible to use DependencyResolver and register Castle Windsor with MVC but

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:21:51+00:00Added an answer on May 31, 2026 at 6:21 pm

    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.

    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<IHttpController>(controllerName);
            controllerContext.Controller = controller;
            controllerContext.ControllerDescriptor = new HttpControllerDescriptor(configuration, controllerName, controller.GetType());
    
            return controllerContext.Controller;
        }
    
        public void ReleaseController(IHttpController controller)
        {
            kernel.ReleaseComponent(controller);
        }
    }
    

    The tricky part was registration it seems to involved registering a whole bunch of other stuff. This is what I ended up with.

    container.Register(Component.For<IHttpControllerFactory>().ImplementedBy<WindsorHttpControllerFactory>().LifeStyle.Singleton);
    container.Register(Component.For<System.Web.Http.Common.ILogger>().ImplementedBy<MyLogger>().LifeStyle.Singleton);
    container.Register(Component.For<IFormatterSelector>().ImplementedBy<FormatterSelector>().LifeStyle.Singleton);
    container.Register(Component.For<IHttpControllerActivator>().ImplementedBy<DefaultHttpControllerActivator>().LifeStyle.Transient);
    container.Register(Component.For<IHttpActionSelector>().ImplementedBy<ApiControllerActionSelector>().LifeStyle.Transient);
    container.Register(Component.For<IActionValueBinder>().ImplementedBy<DefaultActionValueBinder>().LifeStyle.Transient);
    container.Register(Component.For<IHttpActionInvoker>().ImplementedBy<ApiControllerActionInvoker>().LifeStyle.Transient);
    container.Register(Component.For<System.Web.Http.Metadata.ModelMetadataProvider>().ImplementedBy<System.Web.Http.Metadata.Providers.CachedDataAnnotationsModelMetadataProvider>().LifeStyle.Transient);
    container.Register(Component.For<HttpConfiguration>().Instance(configuration));
    
    //Register all api controllers
    container.Register(AllTypes.FromAssembly(assemblyToRegister)
                                .BasedOn<IHttpController>()
                                .Configure(registration => registration.Named(registration.ServiceType.Name.ToLower().Replace("controller", "")).LifeStyle.Transient));
    
    //Register WindsorHttpControllerFactory with Service resolver
    GlobalConfiguration.Configuration.ServiceResolver.SetService(typeof(IHttpControllerFactory), container.Resolve<IHttpControllerFactory>());
    

    I had to create my own implementation of an ILogger you could use a stub version like bellow.

    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<string> messageCallback)
        {
            // Do some logging here eg. you could use log4net
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know its probably possible, but is it practical and doable to try and
I know its probably possible, but is it practical and doable to try and
Know this might be rather basic, but I been trying to figure out how
Know if it's possible to access the iPhone compass in Safari using JavaScript? I
Anyone know if it's possible to databind the ScaleX and ScaleY of a render
I know this might be a no-brainer, but please read on. I also know
I know, I would have thought the answer was obviously no as well, but
I know this is a stupid question, but I've looked for 45 mins now
I know how to use the search feature on JQGrid where you send the
I know that design patterns is generally something that's connected to OO programming, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.