0
私は依存性注入パターンを初めて使用しています。下記のシナリオをご覧ください。今、私の下のコードは緊密に結合されています。私はこれを軽く結合させたいと思っています。C#で統一コンテナにパラメータ化されたコンストラクタクラスを登録するには?
誰かが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>();
を実装している。しかしそのは私を助けていません。
[Unityでパラメータ化されたコンストラクタを持つこのタイプを登録するにはどうすればよいですか?](http://stackoverflow.com/questions/13067496/how-should-i-register-this-type-that-has -parameterized-constructor-in-unity) – dbugger