Prism MEF example
2024-09-26 23:35:12
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.
最新文章
- 从零开始编写自己的C#框架(22)——添加普通列表页面
- linux下查看进程占用端口和端口占用进程命令
- Java的HashSet类
- HashSet HashTable HashMap的区别
- 解决C#的64位打包程序,在64位机器上运行出现BadImageFormatException异常。
- Android——主流分辨率
- 学习总结 for循环--冒泡排序
- Uninstall Tool 3.3.2.5315 简体中文注册版(彻底卸载软件)
- winform DataGridView 导出到Excel表格 分类: WinForm 2014-07-04 10:48 177人阅读 评论(0) 收藏
- Linux操作系统安全(一)
- MYSQL 退出的三个方式
- Extjs中创建Tree菜单【一】
- SAX解析原理示意
- LINUX signal 信号
- 【转】SQL Server 事务隔离级别详解
- 运行pytorch代码遇到的error解决办法
- 在BootStrap的modal中使用Select2搜索框无法输入
- webpack.base.conf.js
- openresty + lua 3、openresty http 调用
- MongoDB:通过mongodump【时间一致性】备份,快速创建secondary复制集节点——更精简的方式2
热门文章
- nodejs中的fiber(纤程)库详解
- CF#538(div2) B. Yet Another Array Partitioning Task 【YY】
- 1、ClassLoader.getResourceAsStream() 与Class.getResourceAsStream()的区别
- QGis 利用Python Console编写脚本进行批量处理
- 【题解】洛谷P1941 [NOIP2014TG] 飞扬的小鸟(背包DP)
- java Scanner和异常
- 微信小程序跳H5页面
- 大数据框架-Zookeeper
- Knowledge Point 20180309 字符串常量池与String,intern()
- 霍金:AI或许能根除疾病和贫穷,但也可能摧毁人类 | GMIC 2017