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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:41:03+00:00 2026-05-31T01:41:03+00:00

I have 2 implementations of an interface where I need to inject the first

  • 0

I have 2 implementations of an interface where I need to inject the first implementation into one service and the second implementation into another. Each service is also injected with other dependencies that do not have multiple implementations.

So far, I have something like this:

public FirstService(IDataRepository dr, IOtherRepository or)
{
    this.DataRepository = dr;
    this.OtherRepository = or;
}

public SecondService(IDataRepository dr, IAnotherRepository ar)
{
    this.DataRepository = dr;
    this.OtherRepository = ar;
}

Then in my bootstrapper I have:

container.RegisterType<IDataRepository, FirstDataRepository>("First");
container.RegisterType<IDataRepository, SecondDataRepository>("Second");
container.RegisterType<IOtherRepository ,OtherRepositor>();
container.RegisterType<IAnotherRepository ,AnotherRepository>();

container.RegisterType<IFirstService, FirstService>(new InjectionConstructor(new ResolvedParameter<IDataRepository>("First")));
container.RegisterType<ISecondService, SecondService>(new InjectionConstructor(new ResolvedParameter<IDataRepository>("Second")));

When I run my application I get the error: “FirstService does not have a constructor that takes the parameters (IDataRepository).”

Do I need to also specify the instance of IOtherRepository that needs to be injected now that I am specifically specifying the instance of IDataRepository that should be injected? Or am I doing something else wrong?

My actual constructor takes 6 arguments and it would be a pain to have to manually inject each of them just because one of them has multiple implementations.

  • 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-31T01:41:04+00:00Added an answer on May 31, 2026 at 1:41 am

    You don’t have to specify the values for the other parameters but you must specify their Type so that Unity can identify which constructor to use.

    The registration for IFirstService would then look like this

    container.RegisterType<IFirstService, FirstService>(new InjectionConstructor(new ResolvedParameter<IDataRepository>("First"), typeof(IOtherRepository)));
    

    The TecX project on codeplex includes the ClozeInjectionConstructor that deals with situations like these where you only want to specify a single parameter. See the sourcecode in the TecX.Unity project.

    Btw: 6 parameters for a constructor are a code smell for the constructor over injection anti-pattern.

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

Sidebar

Related Questions

I have an interface, called IRepository, with two implementations: SqlRepository SqlDualWriterRepository The first implementation
Can a Objective c interface have more than one implementation? Example I could have
I have two implementations of a method, one for value types and another for
I have two implementations of interface IFoo : Foo1 and Foo2 . I need
in my implementation, I have an interface as: ICachingManager . I've got now one
We have an interface IPoller for which we have various implementations. We have a
Does C++ have a proper implementation of interface that does not use vtable? for
I understand that I cannot add preconditions on an interface implementation. I have to
Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView
I have a design like the own shown below, with one interface extending multiple

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.