ninject.extensions.conventions
特定のアセンブリ内のすべての実装をバインドし、バインディングのメタデータとしてアセンブリ名でタグ付けするために使用しています。Get を使用してこれらのアイテムを引き出すことができ、標準として func を提供します。
私が知りたいのは、この関数が解決されたすべての子にも適用されるということですか? 私の心配は、私のロジックは今は機能していますが、子供たちを満たすバインディングを複数回追加すると、ninject がスローされることです。
コードサンプル:
_kernel.Bind(binder => binder.From(new[] { pathToAssembly })
.SelectAllClasses()
.BindAllInterfaces()
.Configure(binding =>
binding.WithMetadata("context",
assemblyName)));
_kernel.Get<IRootDependency>
(metadata => metadata.Get<IRootDependency>("context") ==
assemblyName);
// Bound from convention above.
RootDependencyBase: IRootDependency
{
Public RootDependencyBase(IChildDependency Child) {};
}
// Bound using the convention above with the same MetaData Tag.
ChildDependencyFromSameAssembly : IChildDependency {}
// Bound using a differing convention and does not have the same MetaData tag.
ChildDependencyFromOtherAssembly : IChildDependency {}
上記のサンプルに基づいて、メタデータ フィルターに基づいて IRootDependency が正しいバインディングに解決されることがわかります。
私が見つけようとしているのは、次の真実です。
このフィルターは、依存関係チェーンをフィードしません。IChildDependency は例外をスローします。これは、バインディングで MetaData が指定されていてもクエリされないためです。