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 很好,但是当我告诉 LookForRegistries 时,它没有找到它。

4

1 回答 1

3

IoC、Dll 引用和程序集扫描

于 2009-06-02T19:02:58.390 回答