StructureMap和扫描程序集

8

我有一个使用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,但当我告诉它查找注册表时,它却找不到。
网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接