I have the following Service class constructor:
public class Service : IService
{
private readonly IRepository _repository;
public Service(IRepository repository)
{
_repository = repository;
}
// ...
}
IRepository has two named implementations. I want to Resolve IService but need to set which IRepository implementation should be used (Service should be flexible and I can’t put Dependency attribute to IRepository constructor parameter).
Is there any way to implement it by Unity?
You can use the unity config section to achieve this.
Check this link.
In the config section you can specify the mapping as follows.