I defined 3 interfaces and 3 classes accordingly. Class A depends on interface B, interface B depends on interface C and a concrete class. My sample codes look like
public interface IA
{
}
public class A : IA
{
private IB b;
public A(IB b)
{
this.b = b;
}
}
public interface IB
{
}
public class B : IB
{
private IC c;
private string myValue;
public B(IC c, string myValue)
{
this.c = c;
this.myValue = myValue;
}
}
public interface IC
{
}
public class C : IC
{
}
The special thing is class B, the constructor requires both type and a string (concrete value).
using (IUnityContainer container = new UnityContainer())
{
container.RegisterType<IB, B>()
.RegisterType<IA, A>()
.RegisterType<IC, C>();
IA a = container.Resolve<IA>();
}
How shall I define in code to instruct container to inject both IC and a string value to class B?
You can pass in an InjectionConstructor to your registration.