read

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.

Code listing:

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 ComplexOp yourself!

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!

Karthik


Published on

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

the dotNet way!

experiments w/ asp.net, c#, ruby and many more!!

Back to Home