StructureMapとスキャンアセンブリ
-
21-08-2019 - |
質問
だから、私はのStructureMapを使用する.NETソリューションを持っている、と私はその溶液中のプロジェクトからインターフェイスを実装し、そのためのレジストリエントリを定義する外部のアセンブリを読み込むのStructureMap持っているしたいと思います。
私の解決策のためのStructreMap構成:
ObjectFactory.Initialize(registry =>
{
registry.Scan(assembly =>
{
assembly.TheCallingAssembly();
//Telling StructureMap to sweep a folder called "extensions" directly
//underneath the application root folder for any assemblies found in that folder
assembly.AssembliesFromPath("extensions", addedAssembly => addedAssembly.GetName().Name.ToLower().Contains("extension"));
//Direct StructureMap to add any Registries that it finds in these assemblies, assuming that all the StructureMap directives are
//contained in registry classes
assembly.LookForRegistries();
});
});
かなり簡単、私はディレクトリからのアセンブリコレクションに呼び出し元のアセンブリとアセンブリを追加するためにそれを伝えます。私は、変数のアセンブリをデバッグしたのだが、実際に(拡張ディレクトリからのものを含む)すべてのアセンブリを発見しました。
DLLプロジェクトでは、私は私の元の溶液から別々に作成した、私はインターフェイスの実装を持っている(私は私の元の溶液からのインターフェイスプロジェクトを参照しました)、そして非常に簡単なレジストリを書かれます:
public class ProductMockRegistry : Registry
{
public ProductMockRegistry()
{
ForRequestedType<IProductRepository>().AddInstances(repository =>
{
repository.OfConcreteType<ProductMockRepository>();
});
}
}
私が持っている問題はのStructureMapは、外部DLLでレジストリを見つけることができません、です。それだけで罰金DLLを見つけたが、私はLookForRegistriesにそれを言うとき、それはそれを見つけることができません。
所属していません StackOverflow