PartCreationPolicy on Base Class

Dec 11, 2009 at 5:50 PM

I was under the impression that if I put a PartCreationPolich...NonShared attribute on a base class it would be picked up by derived classes.

It appears this is not happening in an app from the November drop.

Should it be? Or does PartCreationPolicy have to be specifed on the terminal class, or the one that defines the export, or some such detail.

Dec 11, 2009 at 7:16 PM

Hi Kathleen

PartCreationPolicy is not inherited. It must be defined on the most derived class. We discussed having an InheritedPartCreationPolicy, but this was punted for V1.

What is your scenario specifically?

Thanks

Glenn

Dec 11, 2009 at 7:44 PM

The scenario?

A proliferation of attributes.

I have 2-4 attributes on a heck of a lot of classes, and most of it is known by the base class. In a large number of cases, all classes derived from a given base will have the same creation policy. That would ditch one of the attributes. The others, well, you know I want to be able to apply multiple export attributes in a single custom export attribute, but I know you aren't likely to do that. Those can't be supplied at the base because .NET won't allow generics in attributes.

I'm not sure what your reasons were not to inherit it, but for now, it's not inherited.

I believe in an idea world the richness of MEF would almost always be described in a single, preferably custom, attribute.

Dec 12, 2009 at 12:57 AM
Thanks for the feedback Kathleen. We will certainly look into this going forward.
Glenn

From: KathleenDollard [notifications@codeplex.com]
Sent: Friday, December 11, 2009 12:44 PM
To: Glenn Block
Subject: Re: PartCreationPolicy on Base Class [MEF:77881]

From: KathleenDollard

The scenario?

A proliferation of attributes.

I have 2-4 attributes on a heck of a lot of classes, and most of it is known by the base class. In a large number of cases, all classes derived from a given base will have the same creation policy. That would ditch one of the attributes. The others, well, you know I want to be able to apply multiple export attributes in a single custom export attribute, but I know you aren't likely to do that. Those can't be supplied at the base because .NET won't allow generics in attributes.

I'm not sure what your reasons were not to inherit it, but for now, it's not inherited.

I believe in an idea world the richness of MEF would almost always be described in a single, preferably custom, attribute.

Dec 12, 2009 at 1:22 AM
Implementing any sort of inheritance in MEF is not cheap. It is also not simple. It's not enough to bubble you, then also have to deal with overriding behavior, as well as potentially ambiguities if we supported interfaces. It was a signficant amount of design, dev and test work, not tol mention runtime cost.
Thanks
Glenn

From: gblock [notifications@codeplex.com]
Sent: Friday, December 11, 2009 5:58 PM
To: Glenn Block
Subject: Re: PartCreationPolicy on Base Class [MEF:77881]

From: gblock

Thanks for the feedback Kathleen. We will certainly look into this going forward.
Glenn

From: KathleenDollard [notifications@codeplex.com]
Sent: Friday, December 11, 2009 12:44 PM
To: Glenn Block
Subject: Re: PartCreationPolicy on Base Class [MEF:77881]

From: KathleenDollard

The scenario?

A proliferation of attributes.

I have 2-4 attributes on a heck of a lot of classes, and most of it is known by the base class. In a large number of cases, all classes derived from a given base will have the same creation policy. That would ditch one of the attributes. The others, well, you know I want to be able to apply multiple export attributes in a single custom export attribute, but I know you aren't likely to do that. Those can't be supplied at the base because .NET won't allow generics in attributes.

I'm not sure what your reasons were not to inherit it, but for now, it's not inherited.

I believe in an idea world the richness of MEF would almost always be described in a single, preferably custom, attribute.