I am looking at trying to fiter a set of exported test handlers such that some can be used automatically without human interaction and some can be manually used. When they are manual capable they will display a different user control.
I know that you can export/import with a contract name but I wondered what the disadvantage would be using this like so:
[Export(typeof(TestStepHandler))]
[Export("ManualTest", typeof(TestStepHandler))]
That way I could import against the contract name in one ViewModel associated with manual tests and elsewhere import everything in another ViewModel. I guess I would still need a property on a manual test in order for the 'DataTemplate` to work differently when displayed in user mode but this is easy enough to iterate over the imported list.
I did consider that I could use metadata and Lazy
importing and filtering but what advantages would that offer over exporting with and without a contract name?
One advantage of export metadata over export contracts is that with metadata you can alter the filtering of the exported objects dynamically. With attributes its static.
Another disadvantage of what you describe is that you add test-related code in your code-under-test. I don't know if this what you really want.
Appart from the solution using export metadata that you mention there is another way to replace the attributed-model contracts:
Use the Conventions feature of MEF2 which allows for setting up exports/imports without attributes. If you are not familiar with MEF2 Conventions have a look at this series of mini articles. The great thing with Conventions is that it is not a replacement for the Attributed Model. Both can work together. This means that you can use MEF attributes on your assembly and in the tests use Conventions to add the contracts. The important thing with this approach is to allow the test to inject the RegistrationBuilder which will be used for the creation of the catalogs.