2
votes

I want to garanty that unity resolve a constructor parameter using a named registration, for example:

I have two type registrations:

_container.RegisterType<IMyInterface, Implementation1>("implementation1");
_container.RegisterType<IMyInterface, Implementation2>("implementation2");

When unity resolve a class with the following contructor:

public class Example
{
    Example(IMyInterface args)
    {     
    }
}

How should i specify to unity that must resolve using "implementation2" in this case only

1

1 Answers

1
votes

You can configure a type registration in Unity to resolve a constructor argument to a specific named type using the following:

container.RegisterType<IExample, Example>(
    new InjectionConstructor(new ResolvedParameter<IMyInterface>("implementation2")));