Related Attributes

These attributes are under namespace System.ComponentModel.Composition

  • Import

    The attribute can be used on fields, properties, parameters. E.g. If a property is defined with the attribute, the property will be created automatically when the object is created.

    Example:
        [Import(RequiredCreationPolicy = CreationPolicy.NonShared)]
public EmployeeGridViewModel Model
{
get
{
return this.Owner.DataContext as EmployeeGridViewModel;
}
set
{
this.Owner.DataContext = value;
}
}
  • ImportingConstructor

    For previous example, how to create an instance of EmployeeGridViewModel? It will need attribute ImportingConstructor.
        [ImportingConstructor]
public EmployeeGridViewModel(IEmployeeService employeeService)
{
this.employeeService = employeeService;
...
}
  • Export: This attribute is used to register a class into MEF.

    Next question is how to create an instance of IEmployeeService, look this:
    [Export(typeof(IEmployeeService))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class EmployeeService : IEmployeeService
{ }

These code registers EmployeeService as an impelement of type IEmployeeService.

  • PartCreationPolicy

    The attribtue is used with attribute Export, tell MEF the class creation policy, implment a singleton policy or create an instance always.

最新文章

  1. 从零开始编写自己的C#框架(22)——添加普通列表页面
  2. linux下查看进程占用端口和端口占用进程命令
  3. Java的HashSet类
  4. HashSet HashTable HashMap的区别
  5. 解决C#的64位打包程序,在64位机器上运行出现BadImageFormatException异常。
  6. Android——主流分辨率
  7. 学习总结 for循环--冒泡排序
  8. Uninstall Tool 3.3.2.5315 简体中文注册版(彻底卸载软件)
  9. winform DataGridView 导出到Excel表格 分类: WinForm 2014-07-04 10:48 177人阅读 评论(0) 收藏
  10. Linux操作系统安全(一)
  11. MYSQL 退出的三个方式
  12. Extjs中创建Tree菜单【一】
  13. SAX解析原理示意
  14. LINUX signal 信号
  15. 【转】SQL Server 事务隔离级别详解
  16. 运行pytorch代码遇到的error解决办法
  17. 在BootStrap的modal中使用Select2搜索框无法输入
  18. webpack.base.conf.js
  19. openresty + lua 3、openresty http 调用
  20. MongoDB:通过mongodump【时间一致性】备份,快速创建secondary复制集节点——更精简的方式2

热门文章

  1. nodejs中的fiber(纤程)库详解
  2. CF#538(div2) B. Yet Another Array Partitioning Task 【YY】
  3. 1、ClassLoader.getResourceAsStream() 与Class.getResourceAsStream()的区别
  4. QGis 利用Python Console编写脚本进行批量处理
  5. 【题解】洛谷P1941 [NOIP2014TG] 飞扬的小鸟(背包DP)
  6. java Scanner和异常
  7. 微信小程序跳H5页面
  8. 大数据框架-Zookeeper
  9. Knowledge Point 20180309 字符串常量池与String,intern()
  10. 霍金:AI或许能根除疾病和贫穷,但也可能摧毁人类 | GMIC 2017