Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StructureMap and scanning assemblies

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.

like image 648
Eric C Avatar asked Feb 03 '09 18:02

Eric C


1 Answers

IoC, Dll References, and Assembly Scanning

like image 98
Jeffrey Knight Avatar answered Sep 27 '22 16:09

Jeffrey Knight