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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:50:57+00:00 2026-05-23T11:50:57+00:00

With Unity (2.0) I register two named interfaces of IFoo , mapped to two

  • 0

With Unity (2.0) I register two named interfaces of IFoo, mapped to two different implementations:

Container
   .RegisterType<IFoo, Foo1>("first")
   .RegisterType<IFoo, Foo2>("second");

Well, I have a service like this:

public class ServiceImpl : IService {

    public ServiceImpl(IFoo foo, IDependency dep, IJustAnother stuff) { ... }

    public MyValueObject[] FindVOs() { ... }

}

If want to register two named services each depending on one IFoo, i write this:

 Container
   .RegisterType<IService, ServiceImpl>(
      "first", 
      new InjectionConstructor(
         new ResolvedParameter<IFoo>("first"),
         new ResolvedParameter<IDependency>(),
         new ResolvedParameter<IJustAnother>()
      )
   )
   .RegisterType<IService, ServiceImpl>(
      "second", 
      new InjectionConstructor(
         new ResolvedParameter<IFoo>("second"),
         new ResolvedParameter<IDependency>(),
         new ResolvedParameter<IJustAnother>()
      )
   )

It works, but I find it ugly and not clever, because for each new implementation of IFoo I need to add two RegisterType calls.
Is there a better way (maybe with an extension)?

Just another question: how Windsor container deal with this? with auto-registration?

* EDIT *

For example, if I need a CompositeService like this:

public class CompositeService : IService {

    public ServiceImpl(IService[] services) { _services = services; }

    public MyValueObject[] FindVOs() { 
       return _services.SelectMany(_ => _.FindVOs() ); 
    }
}

I could register this way:

Container
   .RegisterType<IService, CompositeService>();

and Unity will inject all named registration in the composite constructor. The problem is that this way it works only giving a name to all of the IService. And i can’t inject IFoo[] instead of IService because IFoo is used only by ServiceImpl which is a particular implementation of IService. This is the reason I asked if there is a better way to register them, avoiding redundancy, in Unity.

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

    I solved writing a UnityContainerExtension (with its own BuilderStrategy), that allows me to do this:

    Container
       .RegisterType<IFoo, Foo1>("first")
       .RegisterType<IFoo, Foo2>("second")
    
       .RegisterType<IService, ServiceImpl>(
           new InjectionPropagator<IFoo>()
       )
    ;
    

    that way i don’t need to register a new named IService for each named IFoo, for me very useful because I can add named IFoo registrations in the XML configuration file.

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

Sidebar

Related Questions

How to do it in code is explained here: Unity Register two interfaces as
Using Microsoft Unity i register the following type: container.RegisterType(typeof(IRepository<>), typeof(NHibernateRepository<>)); In ASP.NET MVC 2
I've just stumbled upon this: within a Unity container, I want to register IDictionary<TK,
I'd like to auto-register the common/simple services in my unity container. I think the
I have an interface with 3 different implementations. I register the 3 implementations as
How can I configure a dictionary via XML with Unity container? This works: <register
I'm trying to automatically register all reports in a unity container. All reports implement
This question is about Unity Container but I guess it is applicable to any
Is there a way for a unity container to pass itself to an object?
I'm using the MS Unity container to do dependency injection, but a Resolve is

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.