温莎城堡及其自己的配置文件
我使用 Castle Windsor 进行 IoC,并使用以下工厂将配置保存在 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
的文件中。我该怎么做?
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 to place the configuration for Castle Windsor in a file called castle.config
. How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WindsorContainer 将接受配置文件的名称作为构造参数:
您的 castle.config 文件将如下所示:
WindsorContainer will accept the name of the configuration file as a construction parameter:
Your castle.config file would then look like this: