Through the introduction of the previous two articles, I am sure you will understand that there are many useful values in MEF. In the previous article we also discussed the import and export, for export import, today we dig a little bit, well, just a little bit deeper, it will not be difficult, please be assured, if you feel that the article boring, may wish to drink milk while reading.
In the previous article we all exported the entire type (the entire class), but sometimes we might consider exporting only certain members of a class, such as a property or a field.
Let's not talk about the theory, so that everyone can not drink milk, or directly serve the bar. To facilitate testing, the following example writes the components in the current assembly, which is in the same project, and then uses Assemblycatalog to find them.
First, define a public interface IWork.
The interface is then implemented using two classes respectively.
Next, we define a general class that contains two properties, and returns an instance of the Firstwork class and the Secondwork class, respectively.