ImportImplementationsAttribute Klasse
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Zusammen mit wird das ExportImplementationAttribute MEF-Proxy Muster aktiviert, bei dem ein einzelner Komponenten Export als Proxy für die beste, zur Laufzeit ausgewählte Implementierung fungiert. Mit diesem Muster können Komponentenconsumer Sie einfach [importieren], um die Komplexität der Auswahl einer Implementierung zu verbergen.
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
- Vererbung
-
ImportImplementationsAttribute
Beispiele
Ein typisches Beispiel:
Eine Komponenten Vertrags Definition:
interface IService {
void Foo();
}
Standard Implementierung:
[ExportImplementation(typeof(IService))]
[Name("default")]
class DefaultService : IService {...}
Eine weitere Implementierung:
[ExportImplementation(typeof(IService))]
[Name("A better implementation")]
[Order(Before = "default")]
class AdvancedService : IService {...}
Ein Proxy:
[Export(typeof(IService))]
class ProxyService : IService {
[ImportImplementations(typeof(IService))]
IEnumerable<Lazy<IService, IOrderable>> _unorderedImplementations;
public void Foo() {
Orderer.Order(_unorderedImplementations).FirstOrDefault()?.Value.Foo();
}
}
IService wird genutzt:
[Import]
IService service = null;
Konstruktoren
| ImportImplementationsAttribute(Type) |
Erstellt eine neue ImportImplementationsAttribute Instanz. |