微软企业库Unity依赖注入
Unity Application Block 1.0系列(4): 方法调用注入(Method Call Injection )
http://www.cnblogs.com/inrie/archive/2008/04/18/1159014.html
微软企业库Unity学习笔记(二)
http://www.cnblogs.com/rush/archive/2011/04/16/Unity.html
C# Unity使用
http://www.cnblogs.com/Teco/archive/2012/05/10/2494416.html
using Microsoft.Practices.Unity;
ILogger
MockLogger
SpecialLogger
实时
1.ILogger logger= new MockLogger();
2.IUnityContainer container = new UnityContainer();
container.RegisterType<ILogger, MockLogger>();
使用配置文件
1. UnityContainer container = new UnityContainer();
container.LoadConfiguration();
ILogger logger= container.Resolve<ILogger>();
2. UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
IUnityContainer container = new UnityContainer();
section.Containers.Default.Configure(container);
ILogger logger= container.Resolve<ILogger>();
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration" />
</configSections>
...
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<container>
<register type="BusinessLogic.ILogger,Common" mapTo="BusinessLogic.MockLogger,Common" />
</container>
</unity>
注意,Common是该project中的Assembly name,在solution中右键盘该project可以看到.