Quantcast
Channel: Managed Extensibility Framework
Viewing all articles
Browse latest Browse all 265

New Post: Convention-based export with attribute-based metadata

$
0
0

Hello, I'd like to use RegistrationBuilder to export all derived types:

rb.ForTypesDerivedFrom<IFoo>().Export<IFoo>();

I need to have an ability to apply metadata individually at class level:

    [ExportMetadata("Name", "boo")]publicclass Foo1 : IFoo
    {
    }

The way of importing parts is:

    [ImportMany]public IEnumerable<Lazy<IFoo, IFooMeta>> foos;

No parts are discovered, because of lack of metadata. I've read how attributes overwrite convention-based info - link. However, it'd require adding an explicit ExportAttribute to each "Foo" class as well. Then, there is no point in having a RegistrationBuilder.

While I seem to understand the reasoning behind this design, my needs definitely fit in a convention - all classes implementing IFoo should be exported with their metadata. One work-around I can think of is:

 

rb.ForTypesDerivedFrom<IFoo>().Export<IFoo>().AddMetadata("Name", retrieveMetaFunc);

where retrieveMetaFunc is a custom method that extracts required metadata from a type. I'm in search for a cleaner, built-in approach that'd eliminate the need for repetitive ExportAttributes on every class definition. For the sake of example something like this:

rb.ForTypesDerivedFrom<IFoo>().Export<IFoo>().WithMetadata();
Notice I'm not able to use custom export attributes, because I have multiple IFooMeta on each exported part.

 

 


Viewing all articles
Browse latest Browse all 265

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>