I have the following 3 interfaces:
public interface IWcfSvc
public interface IAdventureWorks : IWcfSvc
public interface INorthwind : IWcfSvc
They are all in their own assemblies. What I would like to know is, how can I use MEF to load IAdventureWorks and INorthwind? As you already might have understood, IWcfSvc is the default interface for all other interfaces that will be used by WCF as ServiceContracts.
So far, I am able to use MEF for one specific interface, but I would like to make it dynamic as the WCF service will be self-hosting and it needs to be possible to add new services without changing the core of the self-hosted service.
This situation reminds me of the way IClassifierProvider
is registered in the Visual Studio SDK. While many classifier providers may be exported throughout Visual Studio and its many extensions, in general very few (perhaps only one) apply to any single document you open for editing. To associate particular IClassifierProvider
exports with a limited number of documents, a metadata attribute is applied to the export, e.g. like the following:
[Export(typeof(IClassifierProvider))]
[ContentType("My Content Type")]
public class MyClassifierProvider : IClassifierProvider
Metadata attributes are efficient and well-supported inside MEF. In your application, you can expose them to users in one of the following ways:
Use the standard ExportMetadataAttribute
attribute. Had Visual Studio done this, it might look like the following.
[Export(typeof(IClassifierProvider))]
[ExportMetadata("Content Type", "My Content Type")]
public class MyClassifierProvider : IClassifierProvider
Create custom attributes that reflect the specific metadata you expect your extensions to provide.