I'm using Spring.NET 1.3.2, NHibernate 3.1 and the OSIV pattern in a ASP.NET application.
I have a custom EventListener
that needs to be request scoped because it uses
HttpContext.Current.Items as a constructor dependency.
Since ISession
is also request scoped, I should be able to use Spring.NET to manage these dependencies for me.
The problem is that EventListener
, like IInterceptor
, is a property of ISessionFactory
which is not request scoped (it's a singleton). The mismatch between the web object scopes is problematic.
I tried the following XML snippet, but the conditional expression always yields null. I think this is due to Spring creating EventListener
object at an application level scope, and before HttpContext.Current.Items
has had a chance to be populated.
<object id="EventListener" scope="request" type="MyEventListener,DAL">
<constructor-arg index="0" expression="T(System.Web.HttpContext).Current.Items.Contains('Principal')?T(System.Web.HttpContext).Current.Items['Principal']:null"/>
</object>
So my requirement is:
Configure custom
EventListener
object in Spring so that it is created on a per-request basisEventListener
instantiation must occur late enough in the request lifecycle so that HttpContext.Current.Items['Princpial'] has been populated by a custom IHttpModuleThe
EventListener
instance is injected into the the current OSIVISession