In Unity, how do I inject a named dependency into a constructor with other dependencies?

Multi tool use


In Unity, how do I inject a named dependency into a constructor with other dependencies?
I have a service with some dependencies but 1 of them is a named dependency. So, want to config my Unity container to inject that.
I have some like this:
Register of types in Unity container:
container.RegisterType<IOtherService, Implementation>("SpecificImp);
container.RegisterType<IOtherService, OtherImplementation>("otherImp");
container.RegisterType<IService, Service>(
new InjectionConstructor( // Explicitly specify a constructor
new ResolvedParameter<IOtherService>("SpecificImp") // Resolve parameter of type IRepository using name "Client"
)
);
Service:
puclic class Service : IService
{
private read-only IOtherService _otherService;
private read-only IworkContext _workContext;
public Service(
IOtherService otherService,
IworkContext workContext)
{
_otherService = otherService;
_workContext = workContext;
}
}
But the compiler show me a error,
'Implementation' dont have a contrusctor with 'IOtherService' parameter.
So, who can i config mi container to inject correct implementation?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.