prism4学习笔记6:prism、Mef和Unity、MVVM的关系

 

        我们再前面提到了依赖注入,还举了例子好像是网购,你需要东西,就可以送上门来,网购平台就是我们依赖注入的容器,而MEF和unity就好比淘宝、阿里巴巴、易趣网等网上交易平台。你可以选择其中的一种作为容器,当然不同的容器,服务也会有不同。
        把依赖注入,改成依赖(谁?)注入,这个谁就可以是MEF和unit,也还可以是其他可以依赖注入的容器。有了选择就有了比较,你自然就有下面这些疑问:
一.Mef和unity是不是其中一个以绝对优势成功替代另外一个?
    在prism里面,Mef和unity例子都是分开做了,所以他们关系就不是谁替代谁的问题了,至少现在不是,如果是替代关系,人家也不用费那么多无用功了。

二.如果不是替代关系,那么他们各自有哪些特长?这个E文:
Some of the capabilities provided by both containers include the following:
       .They both register types with the container.
        .They both register instances with the container.
        .They both imperatively create instances of registered types.
        .They both inject instances of registered types into constructors.
        .They both inject instances of registered types into properties.
        .They both have declarative attributes for marking types and dependencies that need to be managed.
        .They both resolve dependencies in an object graph.
Unity provides several capabilities that MEF does not:
         .It resolves concrete types without registration.
         .It resolves open generics.
         .It uses interception to capture calls to objects and add additional functionality to the target object.
MEF provides several capabilities that Unity does not:

         .It discovers assemblies in a directory.
         .It uses XAP file download and assembly discovery.
         .It recomposes properties and collections as new types are discovered.
         .It automatically exports derived types.
         .It is deployed with the .NET Framework.
至于选择时机,也请看E文:

        Unity is mostly used for static dependencies and is more an “internal” technology, meaning outsiders do not need to know that unity is being used in the application.
         MEF should be used for dynamic dependencies, it is grate at dynamically loading components and with the use of attributes it make creating application extensions or an application that can be extended by others easy and streamlined.

       看到了没有,共同点大于差异点。另外要注意一点,MEF是在.net framework里面的,所以对于.net而言 MEF属于“家花”,unity则是“野花”,野花有野花的味,家花有家花的香。


三.从prism到MEF,MVVM,UNITY,一大堆名称把人搞得,这些不都是framework吗?
       举个例子,比如一个武馆,设置好多种拳种的教学,如果你是一个小女子你就选择咏春拳,如果你喜欢刚猛的拳法可以选择八极、洪拳、心意拳,如果你喜欢高深点的就选择太极、八卦、形意.....选好了拳种,是不是就要开练了,武术讲究:内练一口气,外连筋骨皮,练习的时候就要讲究一些要领,瞎来出不了功夫还伤自己。

        将这个套到pirsm上:
         prism就是武馆,提供了一个场地、师资力量、武术器材,有合理的价格,比较完善的服务体系,让你学有所成,学的放心;对于他来说主要是要高效运作,通过这个框架实现程序模块化开发。它是基于应用程序层次的;

         EMF、UNITY就是拳种:是提供依赖注入的容器,你选择咏春拳就给你注入咏春,你选择形意就给你注入形意;是基于模块化组件的;有的武馆有优势的拳种,就好比prism还可以使用其他依赖注入的容器,但是EMF和Unity更优秀些;
         MVVM就是练功的方法:MVVM就是让你可以内外分开练,最后轻松的做到内外合,用这种练功方法效率更高些;MVVM的核心是View的抽象,我们前面说到prism实现页面设计和代码设计的分离,是通过mvvm实现的。
         明白关系了没有,还没有?开个玩笑:那你就是文的不行,武的也不用练,只能去练练健美长几坨肉;


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值