Castle Windsor and its own configuration file
I am using Castle Windsor for IoC, and have the configuration held in the web.config
/app.config
, using 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 my web.config
looking 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'd like开发者_如何学C to place the configuration for Castle Windsor in a file called castle.config
. How do I do this?
WindsorContainer will accept the name of the configuration file as a construction parameter:
public WindsorContainer(string xmlFile)
Summary: Initializes a new instance of the Castle.Windsor.WindsorContainer class using a xml file to configure it. Equivalent to the use of new WindsorContainer(new XmlInterpreter(xmlFile))
Your castle.config file would then look like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<components> ...
精彩评论