我正在开发一个 ASP.NET MVC 应用程序,我想根据 web.config 中编写的设置实例化一个类。
<configSections>
<section name="castle"
type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
</configSections>
<castle>
<components>
<component
id="SqlRepository"
service="GomokuGameAppDomain.IGameRepository, GomokuGameAppDomain"
type="GomokuGameAppDomain.SqlGameRepository, GomokuGameAppDomain"
lifestyle="PerWebRequest">
<parameters>
<connectionString>Data Source=ZOLIQ-PC\SQLEXPRESS;Initial Catalog=Gomoku;Integrated Security=True</connectionString>
</parameters>
</component>
</castle>
...
我想使用这样的东西:
var container =
new WindsorContainer (new XmlInterpreter (new ConfigResource ("castle")));
gameRepository = container.Resolve (typeof (IGameRepository)) as IGameRepository;
我该如何解决这个问题?提前致谢。
为了完整起见,整个代码如下所示:
var container = new WindsorContainer();
container.Install(Castle.Windsor.Installer.Configuration.FromAppConfig());
var gameRepository = container.Resolve<IGameRepository>();
快乐编码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)