Я новичок в шаблоне внедрения зависимостей. Пожалуйста, ознакомьтесь с приведенным ниже сценарием. Прямо сейчас мой код ниже тесно связан. Я хочу сделать это как легко связанный.
Может ли кто-нибудь помочь мне реализовать внедрение зависимостей с помощью Unity?
// Implementation of class A
public class A
{
public B b{get;set;}
public A(B b,string c)
{
this.b=b;
this.A(b,c);
}
}
//Implementation of Class B
public class B
{
public int value1 {get;private set;}
public string stringValue {get;private set;}
public B(int value,string strValue)
{
this.value1=value;
this.stringValue=strValue;
}
}
//Implementation of class C
public class C
{
public void Dosomething()
{
B b=null;
string value="Something";
// Here I need to implement unity to resolve tight coupling
// without creating object of Class A
A a=new A(b,value);
}
}
Я что-то устал, основываясь на возможном дублирующем вопросе. Но все же я сталкиваюсь с той же проблемой.
Как мне зарегистрировать этот тип с параметризованным конструктором в Unity?
Вместо этой строки я реализовал приведенный ниже код
A a=new A(b,value);
var container=new UnityContainer();
container.RegisterType<A>();
container.RegisterType<B>();
A a=new A(b,container.ResolveType<B>();
Но мне это не помогает.