小编Eri*_*c C的帖子

StructureMap和扫描组件

所以,我有一个使用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();
   });
});
Run Code Online (Sandbox Code Playgroud)

非常简单,我告诉它将调用程序集和程序集从目录添加到程序集集合中.我调试了程序集变量,它确实找到了所有程序集(包括扩展目录中的程序集).

在我创建的DLL项目中,我独立于原始解决方案,我有一个接口的实现(我从原始解决方案中引用了interfaces项目),并编写了一个非常简单的注册表:

public class ProductMockRegistry : Registry
{
    public ProductMockRegistry()
    {
        ForRequestedType<IProductRepository>().AddInstances(repository =>
        {
            repository.OfConcreteType<ProductMockRepository>();
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,StructureMap没有在外部DLL中找到注册表.它发现DLL很好,但是当我告诉LookForRegistries时,它找不到它.

structuremap registry assemblies

8
推荐指数
1
解决办法
9938
查看次数

标签 统计

assemblies ×1

registry ×1

structuremap ×1