Freigeben über


ImportImplementationsAttribute Class

Definition

Along with ExportImplementationAttribute enables MEF proxy pattern where a single component export serves as a proxy for the best implementation selected at run time. This pattern allows component consumers to just [Import] it, hiding the complexity of selecting one of implementations.

public ref class ImportImplementationsAttribute : System::ComponentModel::Composition::ImportManyAttribute
public class ImportImplementationsAttribute : System.ComponentModel.Composition.ImportManyAttribute
type ImportImplementationsAttribute = class
    inherit ImportManyAttribute
Public Class ImportImplementationsAttribute
Inherits ImportManyAttribute
Inheritance
ImportImplementationsAttribute

Examples

A typical sample:

A component contract definition:

interface IService {
    void Foo();
}

Default implementation:

[ExportImplementation(typeof(IService))]
[Name("default")]
class DefaultService : IService {...}

Another implementation:

[ExportImplementation(typeof(IService))]
[Name("A better implementation")]
[Order(Before = "default")]
class AdvancedService : IService {...}

A proxy:

[Export(typeof(IService))]
class ProxyService : IService {
   [ImportImplementations(typeof(IService))]
   IEnumerable<Lazy<IService, IOrderable>> _unorderedImplementations;

   public void Foo() {
       Orderer.Order(_unorderedImplementations).FirstOrDefault()?.Value.Foo();
   }
}

Consuming IService:

[Import]
IService service = null;

Constructors

ImportImplementationsAttribute(Type)

Creates new ImportImplementationsAttribute instance.

Applies to