因此,我有一个使用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();
});
});非常简单,我告诉它将调用程序集和目录中的程序集添加到assembly集合中。我已经调试了程序集变量,它确实找到了所有的程序集(包括扩展目录中的程序集)。
在我创建的独立于原始解决方案的DLL项目中,我有一个接口的实现(我引用了原始解决方案中的接口项目),并编写了一个非常简单的注册表:
public class ProductMockRegistry : Registry
{
public ProductMockRegistry()
{
ForRequestedType<IProductRepository>().AddInstances(repository =>
{
repository.OfConcreteType<ProductMockRepository>();
});
}
}我的问题是,StructureMap在外部DLL中找不到注册表。它可以很好地找到DLL,但是当我告诉LookForRegistries时,它找不到它。
发布于 2009-06-02 19:02:58
https://stackoverflow.com/questions/508399
复制相似问题