代码之家  ›  专栏  ›  技术社区  ›  Coppermill

Castle Windsor及其自己的配置文件

  •  3
  • Coppermill  · 技术社区  · 16 年前

    我使用温莎城堡作为国际奥委会的场地,并在 web.config / app.config ,使用以下工厂:

    public static TYPE Factory(string component)
        {
            var windsorContainer = new WindsorContainer(new XmlInterpreter());
            var service = windsorContainer.Resolve<TYPE>(component);
    
            if (service == null)
                throw new ArgumentNullException(string.Format("Unable to find container {0}", component));
    
            return service;
        }
    

    还有我的 Web.CONFIG 看起来像这样:

    <configuration>
      <configSections>
        <section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor"/>
      </configSections>
      <castle>
        <components>
          <component id="Data" service="Data.IData, Data" type="Data.DataService, Data"/>
        </components>
      </castle>
      <appSettings>.......
    

    很好,但我想把温莎城堡的配置放在一个名为 castle.config . 我该怎么做?

    1 回复  |  直到 16 年前
        1
  •  4
  •   stuartd saeed    16 年前

    WindsorContainer将接受配置文件的名称作为构造参数:

    公共WindsorContainer(字符串xmlfile)

    摘要:初始化的新实例 温莎城堡 使用XML文件配置 它。相当于使用新的 WindsorContainer(新 XML解释器(XML文件)

    然后castle.config文件将如下所示:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <components> ...