views:

70

answers:

2

I have a number of folders that all contains MEF parts that should be imported. Is the easiest way to find all the parts to iterate over the folders and create a MEF Aggregating Catalog object?

I need to place the parts in different places in the application based on the folder it was read from. So parts from folder "Test1Parts" should be places under the "Test1" section of the application. Do I have the folder name available somehow or will they all look the same once imported via the Aggregating Catalog?

I have generic parts so I can't really put a attribute on each of them an recompile just to have them show up on a different section in the application.

Another way (if it can't be controlled via the folder structure) is f course to use a configuration file that I read before importing telling what part should go where.

What would be the best approach?

+1  A: 

I'm not 100% clear on what you're trying to do, but I suggest using one Aggregating Catalog for each "section" of your application. Then you'd execute a Compose on each section, based on the part catalog for that section. Each catalog would only include parts from the relevant directories (you could also have some common directories that get loaded into both catalogs). Does that make any sense?

Scott Whitlock
+1  A: 

I think the best way to do this is to have a separate container for each folder along with a corresponding DirectoryCatalog for the parts in that folder. If there are parts that need to be global, then you can have a parent catalog that contains those parts and have child catalogs for each directory.

Daniel Plaisted
Riri
I'm not sure, since I don't really understand how you are using the different groups of parts.
Daniel Plaisted
OK. Thanks a lot anyway. I'll give it a try and see how it turns out.
Riri