Re: [picocontainer-dev] Patch for web ... to close that static getter IoC problem

Paul Hammant <[email protected]> Sat, 21 Jun 2008 13:03:14 -0700
Newsgroups gmane.comp.java.picocontainer.devel
Message-ID <[email protected]>
> what I am always curious about is, whether there is a real need for  
> the
> different containers. Do we really have different component types  
> for the
> sessions or requests or is it that we need separate instances?

It would be possible to have one container and use as(..) to push in  
components to the appropriate scoping level :

   container.as(APP_SCOPE).addComponent(Hibernate.class)
   container.as(SESSION_SCOPE).addComponent(ShoppingCart.class)
   container.as(REQUEST_SCOPE).addComponent(AddToCart.class)

Then as http requests happen, pre-process the whole container, setting  
the right cached session scoped things, and ensuring that none at the  
request level are cached.

For the remaining request, the ThreadLocal caching would make sure  
that the right cached instances were used for the http session and  
request.

> In the
> latter case, there's absolutely no need for thread local containers  
> at all.

You'd only dispense with ThreadLocal if you stored who containers as  
attributes in the session - the way we used to do it. now we just have  
the components wrapped

See 'StoreWrapper' in https://svn.codehaus.org/picocontainer/java/2.x/trunk/pico/container/src/java/org/picocontainer/behaviors/Storing.java

Meaning its a lot smaller to serialize than the whole container.

>
> All you need are different component adapters. Like the  
> ThreadLocalized you
> simply need a RequestScoped or SessionScoped one and you will get a  
> new
> instance for each scope accordingly. The filter might add Picos to the
> different scopes, but why do they have to be thread localized?

Kinda ..

   container.addComponent(Hibernate.class);
   container.addAdapter(new SessionScoped(new  
ConstructorInjection(ShoppingCart.class));
   container.addAdaptert(new RequestScoped(new  
ConstructorInjection(AddToCart.class));

.. I still think it needs thread local to make it work.

- Paul

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email