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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:54:55+00:00 2026-05-20T02:54:55+00:00

Following scenario: We use the Fluent API to register all components in an assembly

  • 0

Following scenario:

We use the Fluent API to register all components in an assembly and two components tyepof(A) with named keys. Another class B with two properties typeof(A) should get the named components injected.

Sample:

public class A : IA {}

public class B : IB
{
    [Named("first")]
    public IA First { get; set; }

    [Named("second")]
    public IA Second { get; set; }
}

// ...

container.Register(Component.For<IA>().Instance(new A(value1)).Named("first"));
container.Register(Component.For<IA>().Instance(new A(value2)).Named("second"));

// ...
var b = container.Resolve<IB>(); // named instances of A get injected to B using the Named attribute

Is this possible with an attribute like Named or only with the Xml Config?

  • 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-20T02:54:55+00:00Added an answer on May 20, 2026 at 2:54 am

    The standard way to do this in Windsor is using service overrides. In your example, when you register B you’d do it like this:

    container.Register(Component.For<IB>().ImplementedBy<B>()
                         .ServiceOverrides(new {First = "first", Second = "second"}));
    

    (there are other ways to express this, check the linked docs)

    Using a Named attribute as you propose pollutes the code with unrelated concerns (B should not care about what As get injected)

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

Sidebar

Related Questions

I have the following scenario and I'm not sure if I should use Class
How should I use the unit of work pattern in the following scenario: I'm
Is it possible to use BackGroundWorker thread in ASP.NET 2.0 for the following scenario,
I am trying to use JQuery UI dialog (modal form) for the following scenario.
I'd like to use the ASP.NET membership provider in the following (low-security) scenario... My
I'm brainstorming some ideas around a pattern to use for the following scenario. I
I have this following scenario namespace A { //... class A { public: static
I have following scenario. Some people use approach 1 and some use approach 2.
I want to use the jQuery UI Datepicker for the following scenario. The user
I am interested in knowing if the following scenario is a good use case

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.