微软扩展框架MEF_第1页
微软扩展框架MEF_第2页
微软扩展框架MEF_第3页
微软扩展框架MEF_第4页
微软扩展框架MEF_第5页
已阅读5页,还剩57页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、managed extensibility framework托管可扩展性框架2011-04-28mefmakesextensibilityfabulousglenn block -mef产品经理一般可扩展应用程序架构app framework框架设计者第三方插件设计者模块设计者导航模块设计者ria extensions, add-ins, and plugins oh my!extensibility implantsturning fat apps into slimmer appsneedgotimportexportmef basicsan application is built o

2、f parts.demomef basicsexport it.import it.compose it.export it.widget1export(typeof(usercontrol)public class widget1 : usercontrol public mainpage() initializecomponent(); public string message getreturn(string) button.content; setbutton.content=value; export导出部件必须包含公共无参构造函数import it.widget1export(t

3、ypeof(usercontrol)public class widget1 : usercontrolimportpublic string message getreturn(string) button.content; setbutton.content=value; importstringimport it.widget1export(typeof(usercontrol)public class widget1 : usercontrolimport(“hellomef.message”)public string message getreturn(string) button

4、.content; setbutton.content=value; import“hellomef.message”import it.mainpageexport(typeof(usercontrol)public class mainpage: usercontrolimportmany(typeof(usercontrol)public ienumerable get;set;importmanyusercontrolcompose it.partintializer: “compose yourself”mainpagecompose public mainpage() initia

5、lizecomponent(); var catalog = new directorycatalog(.); var container = new compositioncontainer(catalog); container.composeparts(this); be different use metadatawidgetwidgetwhere does the widget go?export it - metadatawidget1exportmetadata(“location”,location.top)export(typeof(usercontrol)public cl

6、ass widget1 : usercontrolpublic string message getreturn(string) button.content; setbutton.content=value; exportusercontrol put me in the topimport it - metadatamainpageexport(typeof(usercontrol)public class mainpage: usercontrolimportmany(typeof(usercontrol)public ienumerablelazy get;set;importmany

7、usercontrolhave it your way! custom exportsexport it - metadatawidget1exportmetadata(“location”,location.top)export(typeof(usercontrol)public class widget1 : usercontrolpublic string message getreturn(string) button.content; setbutton.content=value; exportusercontrol put me in the topcustomize it cu

8、stom exportswidget1widget(location=location.top)public class widget1 : usercontrolpublic string message getreturn(string) button.content; setbutton.content=value; exportusercontrol put me in the topdemomef and prismintroducing mef-prism integrationgoal : enable an existing prism application to be fu

9、rther extended through mefenabled mef modules to be added dynamically on the fly.enable mef discovered components to be registered in ioc container (such as unity). introducing mef-prism integrationprism application starts and loads up known modules.introducing mef-prism integrationprism application

10、 can load unknown plugins, by using mef as an abstraction layer.1. plugins are located and added to a mef catalog.serverintroducing mef-prism integrationprism application can load unknown plugins, by using mef as an abstraction layer.2. plugins register dependencies with current ioc container.server

11、introducing mef-prism integrationprism application can load unknown plugins, by using mef as an abstraction layer.3. plugins are activated. dependencies are injected.serverwhere can i get it?mef ships in silverlight 4.0dynamic xap support in sl 4.0 toolkitsilverlight 3.0 support on codeplexmef sourc

12、e ships under mspllearn more:smef.cmefcontrib.c prism/mef cross-platform(s)深入深入mefmefmef的几个核心概念可组合的部件导出导入约定组合使用mef的一般步骤添加需要容器创建的约定的导入创建mef用于发现部件的目录创建组合部件实例的容器通过对容器调用composeparts方法并传入具有导入的实例,来进行组合基元层primitives编程模型attributed model托管层hosting.net composition architecture基元层-生成部件和编程模型的位置system.componentm

13、odel.composition.primitives 基元层是mef的核心和基础。基元定义部件的抽象表现形式在这个架构中开发者可以使用不同的编程模型来使用基元,mef提供一种基于特性编程的编程模型特性化编程模型attributed programming modelsystem.componentmodel.composition编程模型定义部件,导入和导出特性化编程模型使用特性(attribute)根据契约将一般的.net对象标记为部件特性化部件编程模型配合托管层进行查找部件和组合部件托管层-进行组合的位置system.componentmodel.composition.hosting托

14、管层提供了很大的灵活性,可配置性和可扩展性目录提供可用导出和导出的部件定义。它们是mef中用于发现的主要单元typecatalogassemblycatalogdirectorycatalog目录从composablepartcatalog继承,并且是mef的扩展点。自定义目录有多种用途: 从提供全新的编程模型到封装和赛选现有目录通过构造函数导入也成为构造函数注入使用导入构造函数时,mef会假设所有参数都是导入,从而不必使用import特性构造函数参数不支持重新组合控制部件创建策略默认情况下,容器中的所有部件实例都是单例,因为由在容器中导入它们的所有部件共享。如果有时每个导入程序都要获取自己的

15、实例,可以设置创建策略creationpolicy.sharedcreationpolicy.nonsharedcreationpolocy.any导入延迟导出和访问元数据system.lazy使用该api可延迟实例的实例化,直至访问lazy的value属性mef使用lazy进一步扩展lazy,以允许在不实例化基础导出的情况下访问导出元数据tmetadata是元数据的视图类型。元数据视图是接口,用于定义对应所导出元数据中的键的只读属性。访问元数据属性时,mef将动态实现tmetadata,且将基于导出提供的元数据来设置值重新组合此功能允许部件在系统中出现新的匹配导出时自动更新其导入。重新组合在某些方案中十分有用,例如从远程服务器下载部件时,可以启动多个可选视图的下载allowrecomposition=true进行组合时,导入集合将立即替换为包含一组更新过的新的集合有两个目录支持重新组合:directorycatalog通过调用其refresh方法来重新组合aggregatecatalog使用catalogs集合属性向该目录添加目录启动重新组合mef的世界小到属性值的注入构造函数参数的注入服务的注入大到模块的集成第三方插件扩展mef提供的是一个可

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论