castle windsor学习-----IWindsorInstaller 通过配置文件注册(Registering Installers)
- 在config配置文件中配置如下节点
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" /> </configSections> <castle> <installers> <install type="LearnCastleWindsor.CustomerInstaller,LearnCastleWindsor"/> </installers> </castle> </configuration> - 其中CustomerInstaller继承IWindsorInstaller接口
public class CustomerInstaller : IWindsorInstaller { public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register(Component.For<Log>()); } } public class Log { public Log() { Console.WriteLine("Log()"); } }CustomerInstaller类中注册Log服务
- 最后通过一下实现注入
1 container.Install(Configuration.FromAppConfig());
浙公网安备 33010602011771号