MEF Preview 5

Tags: ,
Posted in Development

Just upgraded to MEF preview 5 and thought I would just post a gotcha that had me puzzled for a few minutes. After upgrading none of my exported parts were being picked up after composing an instance of the composition container class. I was exporting my types as per the example below:


    1 [Export("DataTransformation.Task")]

    2 public class Task : DataTransformationTask

    3 {

    4     // ….

    5 }



With MEF preview 5 you have to explicitly pass the type you are exporting in the Export attribute constructor as per below:


    1 [Export("DataTransformation.Task", typeof(DataTransformationTask))]

    2 public class Task : DataTransformationTask

    3 {

    4     // ….

    5 }



If you would like to find out what else has changed I would recommend taking a read through Glenn Block’s blog review here: http://codebetter.com/blogs/glenn.block/archive/2009/04/11/mef-preview-5-changes-and-enhancements.aspx


2 Responses

  1. Glenn Block says:

    Hi Rohland

    Sorry this threw you off! Just to clarify this hit you because you are passing string names for contracts. If you use type for exmple

    [Export(typeof(DataTransformationTask)]

    public class Task : DataTransformationnTask

    {

    }

    You will not be affected. Just out of curiosity, is there a particular reason you are using strings instead of type?

  2. Rohland says:

    Hi Glenn

    No particular reason which means I probably should resort to simply using the type. So far I am really enjoying the framework, very easy to use and completely unobtrusive!

Leave a Reply