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 6736625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:09:08+00:00 2026-05-26T11:09:08+00:00

I need to modify an existing web app to use Castle.Windsor as IOC container.

  • 0

I need to modify an existing web app to use Castle.Windsor as IOC container. It was originally developed with StructureMap.

I am stuck with the following problem.

Lets say I have registered a couple of interfaces and their corresponding implementations:

IFoo -> Foo
IBar -> Bar

Calling container.Resolve<IFoo>() or container.Resolve<IBar>() works just fine. This means that the services are registered correctly.

I have a Web Api class with dependencies on other services, such as IFoo

public class BadRequestErrorHandler : HttpErrorHandler
{
    // services
    public BadRequestErrorHandler(IFoo foo) {...} // has dependency on IFoo
}

In StructureMap I can call:

var test = ObjectFactory.GetInstance<BadRequestErrorHandler>();

this will resolve the IFoo dependency.

Now this does not work with windsor.

How can this be achieved with windsor?

Thanks!

* EDIT *
I was just able to make it work by explicitely registering the BadRequestErrorHandler.

container.Register(Component.For<BadRequestErrorHandler>());

I am just hoping there is a better way to achieve this, that does not involve registering classes that have dependencies. I have a bunch of them…

* EDIT 2 **

To ease the pain, I added a special method to deal with these concrete types.

public T GetInstanceWithAutoRegister<T>()
{
    if (container.Kernel.GetHandler(typeof(T)) == null)
    {
        container.Register(Component.For<T>());
    }
    return container.Resolve<T>();
}

public object GetInstanceWithAutoRegister(Type pluginType)
{
    if (container.Kernel.GetHandler(pluginType) == null)
    {
        container.Register(Component.For(pluginType));
    }
    return container.Resolve(pluginType);
}

not ideal, but at least better than having to explicetly register each type. Hope someone has a better solution

  • 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-26T11:09:09+00:00Added an answer on May 26, 2026 at 11:09 am

    You can achieve what you want by registering an ILazyComponentLoader which is a hook that gets called by Windsor as a “last resort” when a component cannot be resolved.

    In your case, the implementation would probably look somewhat like this:

    public class JustLetWindsorResolveAllConcreteTypes : ILazyComponentLoader
    {
        public IRegistration Load(string key, Type service)
        {
            return Component.For(service);
        }
    }
    

    -and then it should be registered as such:

    container.Register(Component.For<ILazyComponentLoader>()
             .ImplementedBy<JustLetWindsorResolveAllConcreteTypes>());
    

    You can read more about it in the docs.

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

Sidebar

Related Questions

I need to modify an existing Java SE process to expose a web service.
I need to take an existing xml file, and modify just a few attributes
I need to modify the following MySQL statement to include information from a third
Got a c#.net app which I need to modify. The query at the moment
I need to modify the attributes on an existing record in LDAP. It seems
I need to modify an existing project. In this project there are several (many)
I need to modify the SearchResultPageURL property in a Search Box web part in
I need to modify the existing program that does some error logging by writing
I need to modify an existing Java application to display some (static) text in
I need to modify a (xml-)file from Apache Ant. loadfile task allows to load

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.