ImportImplementationsAttribute Classe

Definição

Juntamente com ExportImplementationAttribute habilita o padrão de proxy do MEF em que uma única exportação de componente serve como um proxy para a melhor implementação selecionada em tempo de execução. Esse padrão permite que os consumidores de componentes apenas [importem], ocultando a complexidade de selecionar uma das implementações.

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
Herança
ImportImplementationsAttribute

Exemplos

Um exemplo típico:

         Uma definição de contrato de componente:
interface IService {
    void Foo();
}
         Implementação padrão:
[ExportImplementation(typeof(IService))]
[Name("default")]
class DefaultService : IService {...}
         Outra implementação:
[ExportImplementation(typeof(IService))]
[Name("A better implementation")]
[Order(Before = "default")]
class AdvancedService : IService {...}
         Um proxy:
[Export(typeof(IService))]
class ProxyService : IService {
   [ImportImplementations(typeof(IService))]
   IEnumerable<Lazy<IService, IOrderable>> _unorderedImplementations;

   public void Foo() {
       Orderer.Order(_unorderedImplementations).FirstOrDefault()?.Value.Foo();
   }
}
         Consumindo IService:
[Import]
IService service = null;

Construtores

ImportImplementationsAttribute(Type)

Cria uma nova ImportImplementationsAttribute instância.

Aplica-se a