<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">博客园_风云_分类_Mini DI容器</title><id>http://feed.cnblogs.com/blog/u/13626/category/252330/rss</id><updated>2012-06-04T02:00:30Z</updated><generator>feed.cnblogs.com</generator><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/category/252330.html"/><link rel="self" type="application/atom+xml" href="http://feed.cnblogs.com/blog/u/13626/category/252330/rss"/><entry><id>http://www.cnblogs.com/netcasewqs/archive/2012/05/12/2497638.html</id><title type="text">给Web Api 再加把柴-让它更火起来</title><summary type="text">WebApi 这两天被dudu老大炒的老火了，看来我也需要加把柴了，呵呵。 Ndf WebApi 是基于Ndf的服务分发器引擎，并借助Asp.net 的http原生态无状态协议的基础上搭建起来的，简单易用，不废话，上过程！ 服务端Ndf Web API的实现 需要准备的工具：Visual Studio 2010, NuGet(这两天现学了Nuget 包的制作，虽然去年简单学习并制作了NLite的包，不过早忘光了，看了dudu老大的WebApi介绍，感觉落伍了，抓紧进行了恶补，总算制作了一个NdfWeb Api的Nuget 包了呵呵，在这里要多谢dudu了） 1. 新建一个空的ASP....</summary><published>2012-05-12T15:14:00Z</published><updated>2012-05-12T15:14:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2012/05/12/2497638.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2012/05/12/2497638.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2011/12/19/2293144.html</id><title type="text">为ASP.NET MVC创建一个基于Mini容器的ControllerFactory</title><summary type="text">背景 随着Asp.net mvc的越来越流行，关于和Mvc整合的DI容器也非常的多，而Mini容器一致没有把整合的方案发布出来，以至于不时的收到有些网友询问这些事，于是便有了该文。[源代码从这里下载，Mini容器官方地址]解决方案 创建自定义工厂 public class NLiteControllerFactory : DefaultControllerFactory { private IServiceLocator ServiceLocator; public NLiteControllerFactory(IServiceLocator s...</summary><published>2011-12-19T04:13:00Z</published><updated>2011-12-19T04:13:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2011/12/19/2293144.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2011/12/19/2293144.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2011/04/22/2024967.html</id><title type="text">DI 容器-Mini容器工作机制剖析(下篇）</title><summary type="text">上篇介绍了DI容器最基本功能，组件注册和组件创建和组件获取。这里将陆续把依赖注入进行详细介绍。 1. 看看组件工厂接口-IActivator的代码： /// &lt;summary&gt; /// 组件工厂 /// &lt;/summary&gt; public interface IActivator { /// &lt;summary&gt; /// 创建组件 /// &lt;/summary&gt; /// &lt;param name="ctx"&gt;创建上下文&lt;/param&gt; /// &lt;returns&gt;返回所创建的组件&lt;/retur</summary><published>2011-04-22T09:12:00Z</published><updated>2011-04-22T09:12:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/22/2024967.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/22/2024967.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2011/04/21/2023787.html</id><title type="text">DI 容器-Mini容器工作机制剖析(上篇）</title><summary type="text">DI容器在DotNet 中已经不是什么稀罕东西了，如Castle，Unity，Ninject，StructureMap，Spring，MEF等等，这些DI容器都是老外设计的，国内开发的DI容器是少之又少，Mini容器便是少之又少中的一员。关于Mini容器的介绍,请参考去年7月份写的这篇文章：Mini容器介绍。 DI容器核心功能包含2大件，服务注册表和服务定位器。 服务注册表：掌管服务的配置或注册，服务注册成功后，DI容器会生成组件的元数据信息包含： 组件Id标志（服务定位器根据该标志获取组件实例），如果组件在注册时未提供标志，那么系统根据组件类型动态生成一个标志 组件类型 契约接口集合，一个.</summary><published>2011-04-21T09:45:00Z</published><updated>2011-04-21T09:45:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/21/2023787.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/21/2023787.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2011/04/13/2014684.html</id><title type="text">EmitMapper,AutoMapper,NLiteMapper和手工映射性能大比拼</title><summary type="text">在大比拼之前先讲一个小插曲，我这个人以前比较低调，做了很多好东西仅仅在公司内的朋友圈项目圈内分享，很少在博客园内进行分享，后来在dudu 老大的文章博客园现代化建设——AutoMapper有感便推荐一下OOMapper 组件,于是乎接连写了几篇入门性的介绍使用文章：开发人员必备工具：OOMapperOO Mapper 实践（上篇）OO Mapper 实践（下篇） 在园友Repository兄的NLiteMapper与EmitMapper性能简单比较中了解到NLiteMapper与EmitMapper的性能巨大差距，于是乎进行了两天的性能优化，同时总结了优化过程：一次性能优化最佳实践。在这里非.</summary><published>2011-04-13T04:49:00Z</published><updated>2011-04-13T04:49:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/13/2014684.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/13/2014684.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2011/04/07/2007031.html</id><title type="text">Mini 容器学习笔记12——组合实例</title><summary type="text">在项目中常常会遇到多个组件都实现了同一个契约接口，那么在DI容器中怎么获取实现同一个契约接口的所有组件呢。答案是：IEnumerable&lt;TContract&gt; componets = ServiceLocator.GetAll&lt;TContract&gt;(); 上面的实现方案是目前主流的DI容器的解决方法。但是这种方法是通过服务定位器把资源拉过来的，而不是通过注入的方式推过来的，不符合DI注入传统设计规范。那么怎么能够更优雅的解决此类问题呢，MEF率先提供了一种方案ImportMany的方式来进行注入多个组件，当然MIni容器也不甘落后也很快就赶上了。下面看看Mini容器的例</summary><published>2011-04-07T04:46:00Z</published><updated>2011-04-07T04:46:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/07/2007031.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/07/2007031.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2011/04/07/1772326.html</id><title type="text">Mini 容器学习笔记11——Lazy注入</title><summary type="text">Lazy注入指的是在注入的成员变量或构造函数参数变量或函数参数变量的类型上包裹一个Lazy类型，该注入方式是借鉴了MEF思想。具体代码： [TestFixture] public class LazyInjectionTest:TestBase { [Contract] interface ISimpleContract { } class SimpleComponent : ISimpleContract { } class HostComponent { [Inject] public Lazy&lt;ISimpleContract&gt; contract; } [Test] publi</summary><published>2011-04-07T03:50:00Z</published><updated>2011-04-07T03:50:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/07/1772326.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/07/1772326.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2011/04/07/2007027.html</id><title type="text">Mini 容器学习笔记13——插件注入</title><summary type="text">Mini容器的插件注入是通过InjectMany的方式来注入多个组件的方式进行的，插件的元数据通过标签的方式进行配置，Mini容器在注入插件的过程中同时也可以把插件的元数据一起注入，这和MEF实现插件框架是一样的。 下面看看Mini容器怎样来实现插件架构的。 1. 定义插件接口契约，插件元数据标签以及插件元数据接口 //插件接口 [Contract] public interface IAddIn { void Start();//启动插件 } //插件配置元数据标签 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)].</summary><published>2011-04-07T02:42:00Z</published><updated>2011-04-07T02:42:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/07/2007027.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2011/04/07/2007027.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772312.html</id><title type="text">Mini 容器学习笔记10——方法注入</title><summary type="text">方法注入的条件： 1. 方法必须是实例方法 2. 方法必须有参数 3. 方法上必须贴有标签InjectAttribute 方法注入最佳原则 1. 当需要注入的方法的访问权限是私有时，应该把方法所属的类标记为密封类，具体原因请大家猜一猜。 2. 当类标记为密封类时，该类应该实现一个或多个契约接口（当如果需要对该类进行Aop拦截时，可以进行接口代理）样例代码学习： class Person4 : IPerson { public string Name { get; set; } public IHorse Horse { get; private set; } public bool HasVi</summary><published>2010-07-06T09:44:00Z</published><updated>2010-07-06T09:44:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772312.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772312.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772303.html</id><title type="text">Mini 容器学习笔记9——属性注入</title><summary type="text">属性注入的条件： 1. 属性必须是实例字段 2. 属性上必须贴有标签InjectAttribute或InjectManyAttribute 3. 属性必须有Setter访问器 4. 属性不能是索引属性 属性注入最佳原则 1. 当需要注入的属性的访问权限是私有时，应该把属性所属的类标记为密封类，具体原因请大家猜一猜。 2. 当类标记为密封类时，该类应该实现一个或多个契约接口（当如果需要对该类进行Aop拦截时，可以进行接口代理）样例代码学习： [TestFixture] public class PropertyInjectionTest : TestBase { [Contract] inter</summary><published>2010-07-06T09:29:00Z</published><updated>2010-07-06T09:29:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772303.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772303.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772286.html</id><title type="text">Mini 容器学习笔记8——字段注入</title><summary type="text">字段注入的条件： 1. 字段必须是实例字段 2. 字段不能是只读字段 3. 字段上必须贴有标签InjectAttribute或InjectManyAttribute字段注入最佳原则1. 当需要注入的字段的访问权限是私有时，应该把字段所属的类标记为密封类，具体原因请大家猜一猜。2. 当类标记为密封类时，该类应该实现一个或多个契约接口（当如果需要对该类进行Aop拦截时，可以进行接口代理）样例代码学习： [Contract] interface ISampleContract { void Test(); } [Contract] interface IFieldContract { } seale</summary><published>2010-07-06T09:16:00Z</published><updated>2010-07-06T09:16:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772286.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772286.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772255.html</id><title type="text">Mini 容器介绍</title><summary type="text">背景 最早在开发Mbs 中的插件架构时用服务定位器和服务注册表来屏蔽各大DI容器的差异，后来为了更深入的研究DI 容器的内部实现机制，便开发了Mbs DI容器-&gt;Mini容器前身，在开发过程中借鉴了Castle，Unity，Ninject，StructureMap，Spring等思想尤其是Castle容器的工厂以及生命周期管理器等思想。最近一段时间不太忙便重新整理Mbs框架，由于Mbs框架命名不是太好（最早是开发消息总线的），不能描述框架具体包含什么内容，于是便开发Nlite 框架，该框架旨在提供一个轻量级的组件库（DI，Aop,MessageBus, MVP,AddIn,OO Mapp</summary><published>2010-07-06T08:48:00Z</published><updated>2010-07-06T08:48:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772255.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772255.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772176.html</id><title type="text">Mini 容器学习目录</title><summary type="text">Mini 容器学习笔记1——环境搭建(基础篇)Mini 容器学习笔记2——组件元数据(基础篇)Mini 容器学习笔记3——组件的注册(基础篇)Mini 容器学习笔记4——组件的生命周期(应用篇)Mini 容器学习笔记5——组件的获取Mini 容器学习笔记6——组件的获取(应用)Mini 容器学习笔记7——构造函数注入Mini 容器学习笔记8——字段注入Mini 容器学习笔记9——属性注入Mini 容器学习笔记10——方法注入Mini 容器学习笔记11——Lazy注入Mini 容器学习笔记12——组合实例Mini 容器学习笔记13——插件注入Mini 容器学习笔记14——异常处理Mini 容器学</summary><published>2010-07-06T07:29:00Z</published><updated>2010-07-06T07:29:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772176.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772176.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772168.html</id><title type="text">Mini 容器学习笔记7——构造函数注入</title><summary type="text">组件工厂在创建组件时将通过一定的策略选定特定的构造函数，然后进行构造。构造函数的选择策略是：1. 如果遍历的构造函数如果含有参数，那么容器先检查创建上下文中是否含有指定的参数数组或命名参数字典，如果有则选择该构造函数，反之则遍历构造函数的参数，判断每一个参数是否可以进行注入，如果都可以进行注入则选择该构造函数2. 如果构造函数没有参数则选择该构造函数3. 将上面的两个步骤生成的构造函数列表进行按照构造函数参数的个数进行降序排列（构造函数的选择原则是参数越多将被首先选择） 4. 在步骤3的列表 中找出贴有InjectAttribute标签的构造函数，如果找到则选择该构造函数，如果找不到则选择步骤</summary><published>2010-07-06T07:16:00Z</published><updated>2010-07-06T07:16:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772168.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772168.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772105.html</id><title type="text">Mini 容器学习笔记5—— 组件的获取</title><summary type="text">Mini容器主要实现了两个接口，一个是服务注册表接口，一个是服务定位器接口。那么组件的获取就要依靠服务定位器接口IServiceLocator。 IServiceLocator接口的定义：public interface IServiceLocator : IServiceProvider,IDisposable{ object Get(string id); object Get(Type serviceType); object Get(string id, IDictionary&lt;string, object&gt; args); object Get(Type serviceTy</summary><published>2010-07-06T06:10:00Z</published><updated>2010-07-06T06:10:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772105.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772105.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772085.html</id><title type="text">Mini 容器学习笔记4——组件的生命周期(应用篇)</title><summary type="text">Mini容器支持6中生命周期类型： 1. Singleton :单利类型(缺省组件都是单利类型的生命周期，由容器进行托管的） [Test] public void SingletonLifestyleTest() { ServiceRegistry.Register&lt;Person&gt;(); var person = ServiceLocator.Get&lt;IPerson&gt;(); Assert.IsTrue(person != null); var person2 = ServiceLocator.Get&lt;IPerson&gt;(); Assert.IsTrue(per</summary><published>2010-07-06T05:54:00Z</published><updated>2010-07-06T05:54:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772085.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772085.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772031.html</id><title type="text">Mini 容器学习笔记1——环境搭建(基础篇)</title><summary type="text">一. 环境下载到Mini 容器的官方网站下载NLite框架的二进制文件，下载并解压后就可以了。我们使用NLite框架需要用到下面的文件：NLite.dll(必要)二. 建立NLite应用程序 新建一个控制台应用程序 HostMini 添加NLite.dll 引用 添加命名空间：using NLite;using NLite.Mini; 在主函数中添加创建Mini容器的代码：var container = new Kernel(); 创建契约接口IMessageSender 创建组件EmailSender 通过服务注册表注册组件EmailSender 通过服务定位器获取契约接口 调用契约方法： </summary><published>2010-07-06T05:06:00Z</published><updated>2010-07-06T05:06:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772031.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772031.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772047.html</id><title type="text">Mini 容器学习笔记3——组件的注册(基础篇)</title><summary type="text">Mini容器主要实现了两个接口，一个是服务注册表接口，一个是服务定位器接口。那么组件的注册就要依靠服务注册表接口IServiceRegistry了。IServiceRegistry接口的定义： public interface IServiceRegistry { IServiceRegistry Register(IComponentInfo info);//通过组件元数据注册组件到容器中 IServiceRegistry RegisterInstance(string id, object instance);//注册实例 IServiceRegistry RegisterInstance</summary><published>2010-07-06T05:01:00Z</published><updated>2010-07-06T05:01:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772047.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772047.html"/><content type="html"/></entry><entry><id>http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772030.html</id><title type="text">Mini 容器学习笔记2——组件元数据(基础篇)</title><summary type="text">通过上一篇文章简单学习了，环境搭建，这一篇将学习Mini容器的组件注册API的使用方法。当组件注册后，系统都会自动创建一个组件元数据类IComponentInfo 来对该组件进行绑定，系统根据组件元数据进行组件创建，依赖注入，动态代理植入，组件查找定位等，组件元数据在DI容器中的地位是非常重要的。组件元数据定义了以下几个重要的成员：组件Id属性：通过该Id可以唯一标记一个组件，服务定位器可以通过组件Id获取组件实例，当注册组件时如果没有提供组件Id，系统会自动根据组件类型的全名自动生成ServiceRegistry.Register&lt;Person&gt;("person&amp;quo</summary><published>2010-07-06T04:18:00Z</published><updated>2010-07-06T04:18:00Z</updated><author><name>风云</name><uri>http://www.cnblogs.com/netcasewqs/</uri></author><link rel="alternate" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772030.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/netcasewqs/archive/2010/07/06/1772030.html"/><content type="html"/></entry></feed>
