StructureMap和扫描程序集
问题描述:
所以,我有一个使用StructureMap的.NET解决方案,并且我想让StructureMap读取一个外部程序集,该程序集实现了该解决方案中项目的接口并为其定义了注册表项。我的解决方案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时,它找不到它。