3
我使用温莎城堡进行了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
的文件中。我该怎么做呢?
注意,我们在每次创建一个新的容器你需要解析一个组件。这不仅**效率很低,而且还会以这种方式失去生活方式管理等功能。相反,请为每个应用程序创建一个容器。 – 2010-03-31 12:27:45
请告诉我你只是在你的应用程序的每个生命周期中调用这个方法'Factory' ... – 2010-03-31 15:39:58
它只是作为WCF服务的构造函数的一部分被调用,是吗? – Coppermill 2010-04-01 08:03:59