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.

Prism MEF example的更多相关文章

  1. Prism&MEF构建开发框架 (一)

    Shell框架XECA shell.xaml主要起到是一个容器或壳的作用 <Window x:Class="XECA.Shell"      xmlns="http ...

  2. Prism&MEF构建开发框架 (三)

    菜单管控模块EntityFW 菜单的加载采用MEF技术,程序实现思路: 1 .主菜单加载页面MainMenuView.xaml指向MenuRegion 2. 菜单Item点击及内容加载,采用订阅模式, ...

  3. 一步步实现 Prism + MEF(一)--- 搭建框架

    第一步:构建一个名为Bootstrapper的类作为引导程序. class Bootstrapper : MefBootstrapper { } 第二步:在MainWindow窗体中添加一个Coont ...

  4. 一步步实现 Prism + MEF(二)--- 绑定命令

    Prism程序集为我们提供了DelegateCommand命令,使用该命令可实现窗口直接绑定.第一步:在ViewModel中定义一个DelegateCommand属性. public Delegate ...

  5. Prism&MEF构建开发框架

    系统框架构想效果图 平台简单由左侧菜单和右侧内容区以及顶部系统和用户信息区构成 菜单根据系统模块动态加载 右侧,根据左侧选中菜单动态加载子模块,子模块集合以tab选项卡方式布局 系统模块划分为Shel ...

  6. 【翻译】WPF应用程序模块化开发快速入门(使用Prism+MEF)

    编译并运行快速入门 需要在VisualStudio 2010上运行此快速入门示例 代码下载:ModularityWithMef.zip 先重新生成解决方案 再按F5运行此示例 说明: 在此快速入门示例 ...

  7. Prism for WPF初探(构建简单的模块化开发框架)

    先简单的介绍一下Prism框架,引用微软官方的解释: Prism provides guidance to help you more easily design and build, flexibl ...

  8. Prism6下的MEF:基于微软企业库的Cache

    通常,应用程序可以将那些频繁访问的数据,以及那些需要大量处理时间来创建的数据存储在内存中,从而提高性能.基于微软的企业库,我们的快速创建一个缓存的实现. 新建PrismSample.Infrastru ...

  9. Prism for WPF

    Prism for WPF Prism for WPF初探(构建简单的模块化开发框架)   先简单的介绍一下Prism框架,引用微软官方的解释: Prism provides guidance to ...

随机推荐

  1. 4.spriing:Bean的生命周期/工厂方法配置Bean/FactoryBean

    1.Bean的生命周期 scope:singleton/prototype 1)spring容器管理singleton作用的生命周期,spring能够精确知道Bean合适创建,何时初始化完成,以及何时 ...

  2. Linux磁盘分区,挂载

    分区基础知识 分区的方式:   1) mbr分区:     1.最多支持四个主分区     2.系统只能安装在主分区     3.扩展分区要占一个主分区     4.MBR最大只支持2TB,但拥有最好 ...

  3. python中__init__.py与def __init__(self)的使用

    一直对__init__的使用很迷茫,这里系统的学习了解下 1.__init__.py文件-package的标识 python中每个package实际上是一个目录(Directory),程序运行时如何识 ...

  4. 使用npm uninstall卸载express无效

    最近在看<node.js开发指南>学习node.js,因为书是2012年的书,对应的各种软件.包的版本就特别老,其中第五章用到express,书中版本用的是2.X版本,而我这边通过npm ...

  5. mongodb副本集优先级设置

    在设置mongodb副本集时,Primary节点.second节点,仲裁节点,有可能资源配置(CPU或者内存)不均衡,所以要求某些节点不能成为Primary我们知道mongodb的设置:  除了仲裁节 ...

  6. python-使用递归实现二分法

    在上一篇中简单介绍了递归的使用,请戳这里 .  在此篇中,主要介绍如何用递归实现二分法. 在使用二分法之前,首先要有个前提,那就是这个数组必须是有序数组.主要的思路为: ①先取出数组中的一个中间值, ...

  7. 检查BUG插件 代码规范(Findbugs)插件 安装以及使用(idea)

    使用findbugs进行检查代码规范 Findbugs很多人都并不陌生,Eclipse中有插件可以帮助查找代码中隐藏的bug,IDEA中也有这款插件.这个插件可以帮助我们查找隐藏的bug,比较重要的功 ...

  8. Java 循环结构

    Java 循环结构 - for, while 及 do...while 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. Java中有三种主要的循环结构: whi ...

  9. Java 编码规范(转)

    本文转自:http://www.javaranger.com/archives/390 文章总结出了java编码过程中的一些规范,以便参考. 1.合理组织代码层次,分层清晰:controller.lo ...

  10. react系列(六)Redux Saga

    在Redux中常要管理异步操作,目前社区流行的有Redux-Saga.Redux-thunk等.在管理复杂应用时,推荐使用Redux-Saga,它提供了用 generator 书写类同步代码的能力. ...