It’s MEF time again! This time I am going to discuss a little bit about the
ImportConstructor attribute. As the name of the attribute suggests, it is used to “import” dependencies in to constructor parameters. Consider the following snippet which demonstrates this.
ComplexOp implements the
IComplexOp contract. The constructor for
ComplexOp “imports” the
IGreeting contract. In order to make this work, the
ImportingConstructor attribute is used on the constructor of
ComplexOp (line 32). Fair enough! But, how do you put this in to use? Obviously you cannot create an instance of
I am sure you guessed the answer! Yes! We just have to use more MEF, and inject
IComplexOp as a dependency in the class that has to consume the
ComplexOp dependency (line 56)!
That’s it! Hope you enjoyed this no nonsense post
Also check out the following blog posts related to MEF!