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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:16:36+00:00 2026-06-05T15:16:36+00:00

Update: Is there a way to achieve what I’m trying to do in an

  • 0

Update: Is there a way to achieve what I’m trying to do in an IoC framework other than Windsor? Windsor will handle the controllers fine but won’t resolve anything else. I’m sure it’s my fault but I’m following the tutorial verbatim and objects are not resolving with ctor injection, they are still null despite doing the registers and resolves. I’ve since scrapped my DI code and have manual injection for now because the project is time sensitive. Hoping to get DI worked out before deadline.


I have a solution that has multiple classes that all implement the same interface

As a simple example, the Interface

public interface IMyInterface {
    string GetString();
    int GetInt();
   ...
}

The concrete classes

public class MyClassOne : IMyInterface {
    public string GetString() {
        ....
    }
    public int GetInt() {
        ....
    }
}

public class MyClassTwo : IMyInterface {
    public string GetString() {
        ....
    }
    public int GetInt() {
        ....
    }
}

Now these classes will be injected where needed into layers above them like:

public class HomeController {

    private readonly IMyInterface myInterface;

    public HomeController() {}

    public HomeController(IMyInterface _myInterface) {
        myInterface = _myInterface
    }
    ...
}

public class OtherController {

    private readonly IMyInterface myInterface;

    public OtherController() {}

    public OtherController(IMyInterface _myInterface) {
        myInterface = _myInterface
    }
    ...
}

Both controllers are getting injected with the same interface.

When it comes to resolving these interfaces with the proper concrete class in my IoC, how do I differentiate that HomeController needs an instance of MyClassOne and OtherController needs an instance of MyClassTwo?

How do I bind two different concrete classes to the same interface in the IoC? I don’t want to create 2 different interfaces as that breaks the DRY rule and doesn’t make sense anyway.

In Castle Windsor I would have 2 lines like this:

container.Register(Component.For<IMyInterface>().ImplementedBy<MyClassOne>());
container.Register(Component.For<IMyInterface>().ImplementedBy<MyClassTwo>());

This won’t work because I will only ever get a copy of MyClassTwo because it’s the last one registered for the interface.

Like I said, I don’t get how I can do it without creating specific interfaces for each concrete, doing that breaks not only DRY rules but basic OOP as well. How do I achieve this?


Update based on Mark Polsen’s answer


Here is my current IoC, where would the .Resolve statements go? I don’ see anything in the Windsor docs

public class Dependency : IDependency {

    private readonly WindsorContainer container = new WindsorContainer();

    private IDependency() {
    }

    public IDependency AddWeb() {
        ...

        container.Register(Component.For<IListItemRepository>().ImplementedBy<ProgramTypeRepository>().Named("ProgramTypeList"));
        container.Register(Component.For<IListItemRepository>().ImplementedBy<IndexTypeRepository>().Named("IndexTypeList"));

        return this;
    }

    public static IDependency Start() {
        return new IDependency();
    }
}
  • 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-05T15:16:37+00:00Added an answer on June 5, 2026 at 3:16 pm

    You should be able to accomplish it with named component registration.

    container.Register(Component.For<IMyInterface>().ImplementedBy<MyClassOne>().Named("One"));
    container.Register(Component.For<IMyInterface>().ImplementedBy<MyClassTwo>().Named("Two"));
    

    and then resolve them with

    kernel.Resolve<IMyInterface>("One");
    

    or

    kernel.Resolve<IMyInterface>("Two");
    

    See: To specify a name for the component

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

Sidebar

Related Questions

Is there any way to update nested documents by id or some other field?
Is there any way to update my beta testing application on windows phone marketplace?
is there a way to update a binding before or when a command is
I there a way to update a row without mentioning fields name ? I
Is there a way to get an update by email when a user updates
Is there any way to set/update values in the settings.bundle from within your app.
Is there a way to update only the parent UpdatePanel without updating the child
Is there any way to update a table layout after it has been created?
Is there a way to achieve the iTunes style modal view controller chain (see
Is there a way to achieve inter-process (or threading) communication in PHP, but still

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.