I would like to dynamically apply the MEF Export attribute to a type at run-time, exactly as if the type had had an Export attribute applied at compile time.
Is there a simple way to do this?
Barring that, is there a complex way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you can afford to use .NET 4.5 (which means dropping windows XP support), you can now use MEF’s attribute-less registration aka Convention Model.
In .NET4 or earlier MEF preview releases this is not supported out of the box, but MEF can still be extended by creating your own implementations of ExportProvider or ComposablePartCatalog.
The MEF Contrib Fluent Definition Provider is such an implementation which allows you to register imports and exports by method calls.
The MEF Contrib Configurable Definition Provider is another which allows you to set up the imports and exports in an XML file.
Yet another option is to do the registration with Autofac and then use its MEF integration to make the autofac components available to MEF.