2
votes

Currently all of the classes that I have handle their own imports. Using a typical example:

[ImportMany]
private Lazy<ISomeInterface>[] someOfMyInterfaces { get; set; }
public MyConstructor()
{
    AssemblyCatalog catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
    CompositionContainer container = new CompositionContainer(catalog);
    container.ComposeParts(this);
}

Now, I want to use an aggregate catalog and need to change the implementation of all my classes that take imports. I want to put this logic in a centralized place. Basically removing the dependence of my classes to compose their own parts. Are there any good patterns to accomplish this?

1

1 Answers

1
votes

Yes, you definitely don't want to be creating a container in each of your parts. Rather, try to have every part with an import also have an export which is imported by another part. Then in your startup code you create a container and pull a root export from it which will cause all the other parts to get created and their imports satisfied when needed.