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.