Castle Windsor and custom configuration file

I am using Castle Windsor for IoC and have the configuration contained in web.config/ app.configusing the following factory:

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;
    }

and mine web.configlooks like this:

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

Which works fine, but I would like to put the configuration for Castle Windsor in a file called castle.config. How to do it?

+3
source share
1 answer

WindsorContainer will accept the name of the configuration file as a design parameter:

public WindsorContainer (xmlFile string)

: . .WindsorContainer , xml . WindsorContainer ( XmlInterpreter (XMLFILE))

castle.config :

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

Source: https://habr.com/ru/post/1739284/


All Articles