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

  • Home
  • SEARCH
  • 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 8820679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:40:04+00:00 2026-06-14T05:40:04+00:00

I really dont understand what I’m doing wrong here – for some reason the

  • 0

I really dont understand what I’m doing wrong here – for some reason the IControllerFactory i register is not being used, and I end up with a System.ArgumentException:

Type ‘Company.WebApi.Controllers.AController’ does not have a default
constructor

at System.Linq.Expressions.Expression.New(Type type) at
System.Web.Http.Internal.TypeActivator.Create[TBase](Type
instanceType) at
System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage
request, Type controllerType, Func`1& activator) at
System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage
request, HttpControllerDescriptor controllerDescriptor, Type
controllerType)

In Global.asax.cs

protected void Application_Start()
{
    //DI-setup
    var container = new WindsorContainer().Install(new WebWindsorInstaller());

    //set custom controller factory
    var controllerFactory = container.Resolve<IControllerFactory>();
    ControllerBuilder.Current.SetControllerFactory(controllerFactory);

    //register cors
    container.Resolve<ICorsConfig>().RegisterCors(GlobalConfiguration.Configuration);

    //routes
    RegisterRoutes(RouteTable.Routes);
}

My IControllerFactory is based on this article http://keyvan.io/custom-controller-factory-in-asp-net-mvc and is implemented as following

public class ControllerFactory : IControllerFactory
    {
        private readonly IWindsorContainer _container;

        public ControllerFactory(IWindsorContainer container)
        {
            if(container == null)
                throw new ArgumentNullException("container");

            _container = container;
        }

        public IController CreateController(RequestContext requestContext, string controllerName)
        {
            if (string.IsNullOrEmpty(controllerName))
                throw new ArgumentNullException("controllerName");

            var componentName = GetComponentNameFromControllerName(controllerName);

            return _container.Resolve<IController>(componentName);
        }

        public SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
        {
            throw new NotImplementedException();
        }

        public void ReleaseController(IController controller)
        {
            _container.Release(controller);
        }

        static string GetComponentNameFromControllerName(string controllerName)
        {
            var controllerNamespace = typeof (CrudController<>).Namespace;
            return string.Format("{0}.{1}Controller", controllerNamespace, controllerName);
        }
    }

I’ve been staring at this for hours, and really can’t see why this isn’t working. When debugging the ControllerFactory is never hit in any method except the constructor. Anyone see whats wrong or missing here?

(Setting ASP.NET MVC ControllerFactory has no effect does not answer my question)

Edit 1 – Controller

    public class AController : CrudController<AModel>
    {
        public AController(IAHandler aHandler) : base(aHandler)
        {
            ...
        }

        [HttpGet]
        public HttpResponseMessage GetByUser(string aId)
        {
            ...
        }
    }

    public abstract class CrudController<T> : ApiController
        where T : IModel, new()
    {
        protected CrudController(ICrudHandler<T> handler)
        {
            ...
        }

        [HttpGet]
        public HttpResponseMessage Get(string id)
        {
            ...
        }

        [HttpPost]
        public HttpResponseMessage Post(T input)
        {
            ...
        }

        [HttpPut]
        public HttpResponseMessage Put(T input)
        {
            ...
        }
    }

Edit 2 – Installer

    public sealed class WebWindsorInstaller : IWindsorInstaller
    {
        private bool _installComplete;

        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            if(_installComplete)
                return;

            //register self for reuse
            container.Register(Component.For<IWindsorInstaller>().Instance(this));

            //controller factory
            container.Register(
                Component.For<IControllerFactory>().ImplementedBy<ControllerFactory>().LifeStyle.Singleton);

            //Handlers
            container.Register(
                Classes.FromAssemblyContaining<AHandler>().InSameNamespaceAs<AHandler>().WithService.
                    DefaultInterfaces());

            //Models
            container.Register(
                Classes.FromAssemblyContaining<AModel>().InSameNamespaceAs<AModel>().WithService.Self());

            //DI
            container.Register(Component.For<IWindsorContainer>().Instance(container));
            container.Register(Component.For<IDependencyResolver>().ImplementedBy<WindsorDependencyResolver>());

            //Controllers
            container.Register(Classes
                .FromAssemblyContaining<AController>()
                .BasedOn<IHttpController>()
                .LifestyleScoped());

            //repositories
            container.Register(
                Classes.FromAssemblyContaining<ARepository>().InSameNamespaceAs<ARepository>().WithService.
                    DefaultInterfaces());

            //cors
            container.Register(Component.For<ICorsConfig>().ImplementedBy<CorsConfig>());

            _installComplete = true;
        }
    }
  • 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-06-14T05:40:05+00:00Added an answer on June 14, 2026 at 5:40 am

    From the error messages in your question it looks like you actually want to register WebAPI controllers. It’s important to note that these are not the same as MVC controllers, and do not use the same controller factory (which you are trying to use).

    See Mark Seeman’s post Dependency Injection in ASP.NET Web API with Castle Windsor for details of how to do this for Web API controllers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I dont really understand why this is not working, I am being returned to
I've spent some time looking over other questions but I dont really understand some
I really dont understand how lastIndexOf works. I could not get the usage of
i really dont understand what happen here, its works on most of servers but
I dont really understand whats going on and cant see the difference: I'm downloaded
I am currently learning bash programming and dont really understand why the passing argument
I think shoulda is really neat, but what I don't understand is why some
I have a big problem because i dont understand how the pointers really work
Possible Duplicate: Variable declaration placement in C I really dont understand why when I
Can someone please check out this code, i really dont understand why i got

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.