I have a dependency that I need to inject into one of my classes. This addiction will be a way of life Transient. It in turn has a type dependency Type. This type must be the type of the source class. I'm just wondering if anyone has an idea on how I can register.
See an example:
public interface ICustomer
{
.....
}
public class Customer : ICustomer
{
public Customer(IRegister register)
{ .... }
}
public interface IRegister
{
.....
}
public class Register
{
public Register(Type partentType)
{ .... }
}
public class TestExample
{
public static void TestMe()
{
IRegister myRegister = new Register(typeof(Customer));
ICustomer myCustomer = new Customer(myRegister);
}
}
Now I know that I can call Container.Resolvewhen I want Customer, and then insert Registermanually. But I need to introduce Registerin most of my classes, so this is not so real. Therefore, I need to do this through configuration or through container.Register.
source
share