Posts

Showing posts with the label unity-container

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

Image
Clash 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 workContex...