1. when will this be done? at your application startup ? then there is no HttpSession started yet...
obviously
2. will you configure the DI using an applicationContext? AFAIK there is no mean to reference HttpSession from within objects configured in applicationContext
That was kind of the implicit question, and the reason I initially posted this message in the core container forum. I figured there might be some build-in way to handle these things. using ioc/dep injection for session objects seams like a nice clean way to handle dependancies on session objects
3. you can use a Filter/servlet that extract the cart and put it in a ThredLocal and configure a factory that will read the cart and reference this factory in the destination object. But, is this worth the effort?
I am using spring with webwork and it has a threadlocal action context from which you can retrieve among other things the session map
So writing a filter isn't necessary. Making things a lot easier.
Since I apperently have to come up with my own method I guess I could
take two approaches
1) create a “singleton” proxy bean for the session object that delegates calls to the real object it stores in the session and retrieves it using a threadlocal
2) create the object using a static factory method that creates session objects
Code:
public static Object createInstance(String beanPrototypeName, String sessionkey)
Code:
<bean id="ShoppingCart" class="ShoppingCart" singleton="false" />
<property name="shoppingCart">
<bean class="SessionObjectFactory" factory-method="createInstance" singleton="false">
<constructor-arg>
<idref local="ShoppingCart" />
</constructor-arg>
...
</bean>
</property>
That seems like a cleaner approach
That way I could prototype the session object in the application context
and I wouldn't have to have seperate interface, implementation, proxy classes
Let me know what you think