私はウィンザーを初めて使い、最も基本的なコンストラクタインジェクションを実装しようとしています。どうやら、APIは最近のバージョンよりもずっと多く変更されているので、現在のバージョンのドキュメントは、あなたが既にそれを行う方法を知っていると思われているようで、古いバージョンのドキュメントは古くなっています。ウィンザーの基本コンストラクタインジェクション
public class ConstructorInjectedComponent
{
public IMyComponent Component { get; set; }
public ConstructorInjectedComponent(IMyComponent component)
{
Component = component;
}
}
IMyComponentの簡単な実装があります:
は、私は簡単なテストコンポーネント持っpublic class AMyComponent : IMyComponent
{
public string Name { get; set; }
public AMyComponent()
{
Name = Guid.NewGuid().ToString("N");
}
}
をそして私は何とか私は戻って取得することができるように、ウィンザーと私のタイプを登録したいです依存関係のインスタンスを含むConstructorInjectedComponentのインスタンス:IMyComponent。
私はそうのようなAMyComponentを登録しました:
_container.Register(Component.For(typeof(AMyComponent)));
私はこのようなConstructorInjectedComponentを登録しました:
_container.Register(Component.For(typeof(ConstructorInjectedComponent)));
と
_container.Resolve(typeof(ConstructorInjectedComponent));
でそれを解決しようとしたが、それが失敗します"とする必要がある依存関係があるため、ConstructorInjectedComponentコンポーネントを作成できません満足。
私はConstructorInjectedComponentの依存関係のIDictionaryを渡そうとしています...そして、これはドキュメントが私に失敗するところです。
どのようにその辞書を定義するかわかりません。私はそれを説明する文書を見つけることができません。私はこれを試してみました:
var d = new Dictionary<string, string>() {{"IMyComponent", "AMyComponent"}};
_container.Register(Component.For(typeof(ConstructorInjectedComponent))
.DependsOn(dependencies));
しかし、これは同じ "依存関係を解決する必要がある"エラーで失敗します。
私は間違っていますか?