We are using Unity framework for Dependency injection. I am registerring two concrete implementations for same class. like…
container.RegisterType<IInterface, MyFirstClass>("first");
container.RegisterType<IInterface, MySecondClass>("second");
Now there are few classes which has contructer injection for above interface..
public class Class1
{
private IInterface _myClass
public Class1 (IInterface myClass)
{
_myClass = myClass // // should be instance of MyFirstClass
}
//.. other code
}
public class Class2
{
private IInterface _myClass
public Class2 (IInterface myClass)
{
_myClass = myClass // should be instance of MySecondClass
}
//.. other code
}
So now we want to resolve IInterface selectivly in above two classes. Class1 and Class2.
Class1 should be injeceted with MyFirstClass and Class2 should be injected with MyFirstClass. Is this possible to achieve via Unity framework? If not which other IoC frameworks support this?
Please suggest your opinions.
Try this