ImportImplementationsAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
与 ExportImplementationAttribute 启用 MEF 代理模式,其中单个组件导出作为运行时选择的最佳实现的代理。 此模式允许组件使用者只需 [Import] 它,从而降低了选择某个实现的复杂性。
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 的实例。 |