views:

31

answers:

2

I have some (sort of) Singletons which exist in three context:

  1. Per AppDomain

  2. Per HttpApplication

  3. Per Web Request

Right now, I'm creating a child container per HttpApplication and another child per Web Request. This is necessary because some components SHOULD actually share singleton instances across the three layers. For security and other reasons, there are certain registrations that SHOULD NOT actually share the singleton (one per container).

Does anyone have a suggestion as to how to implement this or how I can limit the visibility of registrations within a container hierarchy?

Thanks.

+1  A: 

Have you tried using lifestyles to solve this problem? A combination of the Singleton and PerWebRequest lifestyles may satisfy your requirements, without requiring child containers.

Stuart Lange
+1  A: 

As Stuart says, lifestyles are the correct extension point to do this. Child containers are not necessary. Per web request comes out of the box in Windsor, and IIRC the Singleton lifestyle (the default one) works per appdomain. The per-HttpApplication lifestyle is implemented in the Castle.Windsor.Lifestyles contrib project.

Mauricio Scheffer