【问题标题】:StructureMap and scanning assembliesStructureMap 和扫描程序集
【发布时间】:2009-02-03 18:48:18
【问题描述】:

所以,我有一个使用 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 时,它没有找到它。

【问题讨论】:

    标签: assemblies registry structuremap


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多