I have a number of assemblies, each supplying their dependencies to Autofac through the use of a class that extends Autofac.Module. I have decorated each of these as a MEF export, e.g:
[Export(typeof(IModule))]
public class ContainerModule : Module
{
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);
}
}
As part of client application startup, I gather together all of these modules, e.g:
var builder = new ContainerBuilder();
var path = "Path to application Bin directory";
var catalog = new DirectoryCatalog(path, "MyApp*.dll");
builder.RegisterComposablePartCatalog(catalog);
container = builder.Build();
When looking at the catalog, I can see all the modules from all the assemblies are present.
The question I have is how do I then instruct Autofac to call the Load method on each of the loaded modules?
I'm thinking some usage of builder.RegisterAssemblyModules but haven't (yet) had a eureka moment of how to tie that into the catalog.
Thanks!
r.
You probably won't be able to do what you want in this way.
By registering the part catalog with the modules in it, you're registering them as components, similar to any other dependency. The only way to get them back out would be to build the container and resolve IEnumerable<IModule>>
but then calling Load won't register the stuff in the modules because the container's already built.
If you want the modules to contribute their registrations to the container, you have to register them with the ContainerBuilder directly, not through the MEF integration.