castle windsor学习-----IWindsorInstaller 通过配置文件注册(Registering Installers)

  1. 在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>
    

      

  2. 其中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服务

  3. 最后通过一下实现注入
    1 container.Install(Configuration.FromAppConfig());

     

posted @ 2017-03-09 21:11  蓝平凡  阅读(274)  评论(0)    收藏  举报