ImportImplementationsAttribute Класс
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Вместе с ExportImplementationAttribute включает шаблон MEF, где единый экспорт одного компонента служит прокси для лучшей реализации, выбранной во время выполнения. Этот шаблон позволяет потребителям компонентов просто [импортировать], скрывая сложность выбора одной из реализаций.
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
- Наследование
-
ImportImplementationsAttribute
Примеры
Типичный пример:
Определение контракта компонента:
interface IService {
void Foo();
}
Реализация по умолчанию:
[ExportImplementation(typeof(IService))]
[Name("default")]
class DefaultService : IService {...}
Другая реализация:
[ExportImplementation(typeof(IService))]
[Name("A better implementation")]
[Order(Before = "default")]
class AdvancedService : IService {...}
Прокси-сервер:
[Export(typeof(IService))]
class ProxyService : IService {
[ImportImplementations(typeof(IService))]
IEnumerable<Lazy<IService, IOrderable>> _unorderedImplementations;
public void Foo() {
Orderer.Order(_unorderedImplementations).FirstOrDefault()?.Value.Foo();
}
}
Использование IService:
[Import]
IService service = null;
Конструкторы
| ImportImplementationsAttribute(Type) |
Создает новый ImportImplementationsAttribute экземпляр. |