StructureMap and scanning assemblies

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 08:38:42

问题


So, I have a .NET solution that uses StructureMap, and I'd like to have StructureMap read an outside assembly that implements an interface from a project in that solution and defines the registry entry for it.

StructreMap configuration for my solution:

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();
   });
});

Pretty straightforward, I tell it to add the calling assembly and the assembly from a directory to the assemblies collection. I've debugged the assemblies variable and it has indeed found all the assemblies (including the one from the extensions directory).

In a DLL project I've created separate from my original solution, I have an implementation of an interface (I've referenced the interfaces project from my original solution), and written a very simple registry:

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

The problem I have is, StructureMap does not find the registry in the external DLL. It finds the DLL just fine, but when I tell it to LookForRegistries, it doesn't find it.


回答1:


IoC, Dll References, and Assembly Scanning



来源:https://stackoverflow.com/questions/508399/structuremap-and-scanning-assemblies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!