开发者

Can IWindsorContainer be instantiated through a static method?

开发者 https://www.devze.com 2023-01-15 01:41 出处:网络
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:

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 == nul开发者_如何学Pythonl)
      {
        _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?


The standard and recommended practice is to have one instance of the container per application.

See these related questions for further information:

  • Usage of IoC Containers; specifically Windsor
  • How to get instance of service in Windsor Castle

And yes, Windsor is thread-safe.

0

精彩评论

暂无评论...
验证码 换一张
取 消