I have a custom type instance that needs to be registered in code:
container.RegisterType( typeof(Isome), myvar);
so it can be used normally like this:
[Import]
ISome var1 ;
How do I get a reference to the container?
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.
I don’t know about Prism, but in MEF you don’t register types with the container – that introduces a dependency that defeats the purpose of decoupling the code.
What you do to make the
ISometype available for MEF to discover is you put an[Export(typeof(ISome))]attribute on your class that implements theISomeinterface.In composition, MEF will see the Import attribute keyed on the ISome interface type, then go looking for a matching Export keyed on the ISome interface type. It will find your implementation class with the Export attribute. MEF will create an instance of the exported class and assign it to the import property for you.
In the composition step, you need to provide a catalog of types or assemblies for MEF to load and do its matchmaking magic. Make sure the assembly that contains your implementation class is in that catalog group.