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

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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.

t,P8XuZ1ilic6KD1OWNXAK1dUBZp,iBAdOJKE6 t 6PoFfQAS
Cy YTfbMaJanCaek4RHWN

Popular posts from this blog

Makefile test if variable is not empty

Visual Studio Code: How to configure includePath for better IntelliSense results

Will Oldham