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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:29:19+00:00 2026-05-21T19:29:19+00:00

If I register a component with the container with a name (don’t worry… contrived

  • 0

If I register a component with the container with a name (don’t worry… contrived example!)

container.Register(Component.For<double>().Instance(Math.PI).Named("pi")

And ask to resolve that service type with a different name

container.Resolve<double>("e")

I get an ComponentNotFound exception. But now if I use the typed factory facility

interface IDoubleFactory { double GetDoubleByName(string name); }

container.Register(  
  Component.For<DoubleSelector, ITypedFactoryComponentSelector>()   
  Component.For<IDoubleFactory>().AsFactory(f => f.SelectedWith<DoubleSelector>())
  Component.For<double>().Instance(Math.PI).Named("pi"))

public class DoubleSelector : DefaultTypedFactoryComponentSelector
{
  protected override string GetComponentName(MethodInfo method, object[] arguments) 
  {
    return arguments[0] as string;
  }
}

and try to use the factory to resolve a bogus name

container.Resolve().GetDoubleByName(“e”)

I get pi back instead of an exception. It appears that having given a name to the ITypedFactoryComponentSelector which did not help, it has fallen back to just using the Type (in this case double) and grabbed the first thing registered against it.

  • 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-21T19:29:20+00:00Added an answer on May 21, 2026 at 7:29 pm

    The answer may be a bug in Windsor 2.5.1. The contract for ITypedFactoryComponentSelector suggests that if you return null for ComponentType but non-null for ComponentName, the lookup will be done by name, and not type. But two problems get in your way if you try to do that.

    According to GitHub sources, code in DefaultTypedFactoryComponentSelector.BuildFactoryComponent calls GetCompatibleArrayItemType on what may be a null ComponentType pointer, which causes an exception. This seems like a bug, plain and simple.

    If you find a way to monkey patch that, then it appears that TypedFactoryComponentResolver.Resolve method doesn’t quite arrange to call the right overloads on the kernel to resolve in cases where ComponentType is null. I’m much less clear whether this is a bug or a lack in my understanding of which IWindsorContainer.Resolve methods do what. That said, a dispatch to the various methods (Resolve<object>(string key), for example) seems to do the trick.

    Both classes are unsealed, so it’s straightforward to fix with derived classes.

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

Sidebar

Related Questions

I did the following: container.Register(Component.For<Dictionary<string, string>>() .Instance(ServiceDictionaryInstance) .Named(serviceDictionary)); The class consumes the component is:
I register my two interfaces on application start as so:- container.Register(Component.For(typeof(IEntityIndexController)).ImplementedBy(typeof(SnippetController)).LifeStyle.Transient); container.Register(Component.For(typeof(ISnippetController)).ImplementedBy(typeof(SnippetController)).LifeStyle.Transient); Then when
If I have defined in config: container.Register( Component.For<X.Y.Z.IActivityService>() .ImplementedBy<X.Y.Z.ActivityService>() .ServiceOverrides(ServiceOverride.ForKey(Listeners).Eq(new [] { typeof(X.Y.Z.DefaultActivityListener).FullName }))
When I use this registration: container.Register( Component .For<IFooFactory>() .ImplementedBy<FooFactory>(), Component .For<IFoo>() .UsingFactoryMethod(kernel => kernel.Resolve<IFooFactory>().CreateFoo())
I want to register a specific instance of an object for a type in
Say I have a component like this public class MyComponent { public MyComponent(string name)
What is the correct way to pass another component into Eq()? _container.Register( Component.For<IDocumentManagementServiceProvider>() .ImplementedBy<DocumentumServiceProvider>()
I need to register open generic of a type in my Windsor Container. How
Let's say I'm developing an application that installs COM component and installer registers them.
using register_shutdown_function I can register code to execute at the end of a PHP

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.