You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by Andrei Ionescu <ai...@yahoo.com> on 2010/04/04 18:01:00 UTC

Picocontainer related question.

I would like to use PicoContainer(alone) in a Click webapplication, but 
I'm not sure how (Spring looks so much different than Pico to use it as 
a starting example, and there aren't any books about Pico :( )

Let's say in the Click-examples instead of Spring to use PicoContainer
but with a little change:
- for all the classes in the org.apache.click.examples.service.* there
is also an Interface for each (those actual classes there being only the 
implementation - maybe even in an "impl" subpackeage)
- everywhere the services are used, only the Interface is used, and the 
implementation is injected, so that the Click Pages are independent of 
the implementation code.
- this would allow to switch the implementation to e.g. a Hibernate 
implementation for the same example, or to test simpler the Service 
layer since dependencies would be separated with those Interfaces.

Would this possible with PicoContainer and Click? Any idea how, or maybe 
an example?
PicoContainer is so much smaller and it looks like it's more accepted 
than Spring in some projects by the management.

Another alternative for decoupling would the Service Provider Pattern 
supported by the JDK (that META-INF/services/ trick), but it seems to 
require separate JARs and it still requires discovery code - not like 
when the implementation would be simply injected.

There's even an old feature request for Pico:
https://issues.apache.org/jira/browse/CLK-384
but it doesn't seem to have a Fix Version, nor a patch from somebody who 
is expert :(.

regards,
Andrei.


Re: Picocontainer related question.

Posted by Bob Schellink <sa...@gmail.com>.
I don't know Pico but for integration I suggest either:

a) a pico factory that can be used in your Pages to lookup services
b) use pico to create your Pages and inject services directly into those pages

For a) you can use a ContextListener at application startup time to configure your pico factory.

For b) you can look at SpringClickServlet on how to use an IOC container to create Pages.

kind regards

bob

On 5/04/2010 2:01 AM, Andrei Ionescu wrote:
> I would like to use PicoContainer(alone) in a Click webapplication, but
> I'm not sure how (Spring looks so much different than Pico to use it as
> a starting example, and there aren't any books about Pico :( )
>
> Let's say in the Click-examples instead of Spring to use PicoContainer
> but with a little change:
> - for all the classes in the org.apache.click.examples.service.* there
> is also an Interface for each (those actual classes there being only the
> implementation - maybe even in an "impl" subpackeage)
> - everywhere the services are used, only the Interface is used, and the
> implementation is injected, so that the Click Pages are independent of
> the implementation code.
> - this would allow to switch the implementation to e.g. a Hibernate
> implementation for the same example, or to test simpler the Service
> layer since dependencies would be separated with those Interfaces.
>
> Would this possible with PicoContainer and Click? Any idea how, or maybe
> an example?
> PicoContainer is so much smaller and it looks like it's more accepted
> than Spring in some projects by the management.
>
> Another alternative for decoupling would the Service Provider Pattern
> supported by the JDK (that META-INF/services/ trick), but it seems to
> require separate JARs and it still requires discovery code - not like
> when the implementation would be simply injected.
>
> There's even an old feature request for Pico:
> https://issues.apache.org/jira/browse/CLK-384
> but it doesn't seem to have a Fix Version, nor a patch from somebody who
> is expert :(.
>
> regards,
> Andrei.
>
>