MEF Export attribute using

Aug 24, 2009 at 11:48 PM

Hi guys !!

I had usual to use my own composition engine but now I would like to use Microsoft’s one.

I have a plug-in engine for explore some rules to pass to a certain class, and I would like to use MEF.
One of the common things I do is have a base abstract class to made all rules to inherit from this abstract class. Something like this:

 

[Export(typeof(CheckRule))]
public abstract class CheckRule { }

 

Also I have a class like this:

 

public class CheckASPNET : CheckRule { }

 

I want to MEF to explore all the derived types of my abstract class without having to mark with Export all my derived class. Can this be possible or is this a bad using to MEF?

 

[ImportMany(typeof(CheckRule))]
public List<CheckRule> Rules
{
    get;
    set;
}

Thanks in advance. Luis.

 

Aug 24, 2009 at 11:59 PM

Hi Luis,

I believe InheritedExport is what you're looking for:

[InheritedExport(typeof(CheckRule))]
public abstract class CheckRule { }

Cheers,

Nick

Aug 25, 2009 at 12:08 AM

Hi nblumhardt,

That’s exactly what I'm looking for. But this class is not included in VS2010.

Thank you!!

Developer
Aug 25, 2009 at 1:10 AM

I don't believe InheritedExport made it into .Net 4 Beta1 (VS 2010 Beta1) so you will need to wait for the next beta or the MEF released here on codeplex.