IWindsorContainer可以通过静态方法实例化吗?
我还在摸索温莎城堡。目前,我所有需要 IWindsorContainer 的页面都通过一个属性实例化自己:
private IWindsorContainer WindsorContainer
{
get
{
if (_windsorContainer == null)
{
_windsorContainer = new WindsorContainer(new XmlInterpreter(Server.MapPath("~/CastleWindsorConfiguration.xml")));
}
return _windsorContainer;
}
}
我有点厌倦了从一个页面到另一个页面复制和粘贴这个属性和支持字段!另外我不太了解 IWindsorContainer 的生命周期。
我更愿意通过某个类的静态属性来获取其中之一,但有谁知道我是否可以认为它是线程安全的?你们如何使用 IWindsorContainer ?
I'm still groping around a bit with Castle Windsor. At the moment all my pages which need an IWindsorContainer instantiate one themselves through a property:
private IWindsorContainer WindsorContainer
{
get
{
if (_windsorContainer == null)
{
_windsorContainer = new WindsorContainer(new XmlInterpreter(Server.MapPath("~/CastleWindsorConfiguration.xml")));
}
return _windsorContainer;
}
}
I'm getting a little tired of copying and pasting this property and the backing field from page to page! Also I don't really understand the life cycle of the IWindsorContainer.
I'd much rather get one of these through a static property of some class, but does anyone know if I can consider it threadsafe? How do you guys work with IWindsorContainer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标准和推荐的做法是每个应用程序有一个容器实例。
有关更多信息,请参阅以下相关问题:
是的,Windsor 是线程安全的。
The standard and recommended practice is to have one instance of the container per application.
See these related questions for further information:
And yes, Windsor is thread-safe.