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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:39:56+00:00 2026-05-26T23:39:56+00:00

I have a component registered with Castle Windsor which depends on a list of

  • 0

I have a component registered with Castle Windsor which depends on a list of components, each of which is represented by an interface. Castle Windsor is configured similar to the code below.

public class WindsorInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        //Allow the container to resolve all IFooComponent 
        //as IEnumerable<IFooComponent>
        container.Kernel.Resolver
           .AddSubResolver(new CollectionResolver(container.Kernel, false));

        container.Register(
            Component
                .For<IMainService>()
                .ImplementedBy<AwesomeMainService>());

        container.Register(
            Component.For<IFooComponent>()
                .ImplementedBy<CoolFooComponent>()
                .Named(typeof (CoolFooComponent).Name),
            Component.For<IFooComponent>()
                .ImplementedBy<FooComponentWithUnresolvedDependancy>()
                .Named(typeof (FooComponentWithUnresolvedDependancy).Name)
            //....
        );
    }
}

AwesomeMainService depends on an IEnumerable<IFooComponent> like below

public class AwesomeMainService : IMainService
{
    public AwesomeMainService(IEnumerable<IFooComponent> fooComponents) 
    { 
        //I could count the fooComponents here but this is a hack
    }
}

Now if one of the IFooComponents is missing a dependency, or Castle Windsor otherwise encounters an exception while instantiating an IFooComponent, the exception is caught by Castle Windsor and not rethrown. When I resolve the registered instance of IMainService everything appears fine because there is at least on instance of IFooComponent which can be created.

//No exception here because there is at least 1 IFooComponent
var plugin = _container.Resolve<IMainService>(); 

How do I handle this error and shut everything down? I would’ve thought there would be an event on the Kernel, but there doesn’t appear to be.

My Fix:

I created a dynamic parameter for AwesomeMainService which counted the number of IFooProcessors registered. The AwesomeMainService then verified that this matched the number of IFooProcessors provided.

public class AwesomeMainService : IMainService
{
    public AwesomeMainService(IEnumerable<IFooComponent> fooComponents, 
                              int expectedProcessorCount)
    { 
        Verify.That(fooComponents.Count == expectedProcessorCount, 
                    "requestProcessors does not match the expected number " +
                    "of processors provided");
    }
}

Then I added this to the AwesomeMainService registration:

.DynamicParameters((kernel, parameters) =>
    {
        parameters["expectedProcessorCount"] =
            container.Kernel.GetAssignableHandlers(typeof (object))
                .Where(
                    h => h.ComponentModel.Service.UnderlyingSystemType ==
                         typeof (IRequestProcessor))
                .Count();
    }));
  • 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-26T23:39:56+00:00Added an answer on May 26, 2026 at 11:39 pm

    This is a known limitation in Windsor 2.5 and earlier. This scenario will fail-fast in Windsor 3.

    In v3 there’s also a new event EmptyCollectionResolving which is raised when a component depends on a collection of IFoos but no component for IFoo is registered in the container.

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

Sidebar

Related Questions

I have what is probably a simple question here about Castle Windsor, which I
Is is possible with the Castle Windsor Container to have one component implement two
Castle Windsor just came out with a Fluent interface for registering components as an
I'm trying to configure Castle Windsor I have a IFileReader interface implemented by FileReader,
I'm using Castle Windsor 3.0. I have a component that should be started automatically
I have registered a component like this in my Global.asax.cs: ContainerBuilder builder = new
Please consider such scenerio: I have component called TMenuItemSelector which has two published properties:
I have a component that is made up of various components such as a
I have a .net application calling to a COM component (C++) which in turn
I have a custom TitleWindow component that is registered to listen for keyboard events

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.