views:

21

answers:

1

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?

+1  A: 

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.

Mauricio Scheffer
Static method here we go! That's all I needed to know - thanks.
David

related questions