I can’t seem to find any articles or links to how to do this and it seems like an obvious problem (eg when you don’t have the source code or want to use existing types not written for MEF in mind)
Share
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’re looking to add an existing object instance to your container, you can use the
CompositionContainer.ComposeExportedValuemethod:The thing you’re really looking for though is probably the new convention-based programming model, which allows you to create parts based on naming conventions rather than attributes, but this feature is only available in .NET 4.5.
Usage example (this will export every type in
myAssemblywhich implementsIControlleras anIController):A good example of how to use MEF’s new convention model can be found here.
Hope this helps.