Discussion:
call to 'as' method erase previous Characteristics
cameleon104
2008-04-08 14:03:23 UTC
Permalink
Hi all,
To perform multiple type of injection, I use this code (I do not know if is
a good idea or not) :
MutablePicoContainer pico = new DefaultPicoContainer();
MutablePicoContainer inject = pico.as(Characteristics.METHOD_INJECTION);
MutablePicoContainer constructor = pico.as(Characteristics.CDI);

A problem appear when I try to use the 'as' method on 'inject' or
'constructor'
This code doesn't work
inject.as(Characteristics.CACHE).addComponent(VoteManager.class,
VoteManagerStd.class);
There are no call on the inject method

This code work
inject.as(Characteristics.METHOD_INJECTION,
Characteristics.CACHE).addComponent(VoteManager.class,
VoteManagerStd.class);
The call on inject method is made

Obviously, the 'Characteristics.METHOD_INJECTION' is lost on the second call
to 'as' method.

Is it normal ? Is it a bug ?

Thanks
--
View this message in context: http://www.nabble.com/call-to-%27as%27-method-erase-previous-Characteristics-tp16558740p16558740.html
Sent from the NanoContainer - PicoContainer - Users mailing list archive at Nabble.com.


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

http://xircles.codehaus.org/manage_email
Paul Hammant
2008-04-08 15:03:21 UTC
Permalink
Hi,
Post by cameleon104
Hi all,
To perform multiple type of injection, I use this code (I do not know if is
MutablePicoContainer pico = new DefaultPicoContainer();
MutablePicoContainer inject =
pico.as(Characteristics.METHOD_INJECTION);
MutablePicoContainer constructor = pico.as(Characteristics.CDI);
A problem appear when I try to use the 'as' method on 'inject' or
'constructor'
This code doesn't work
inject.as(Characteristics.CACHE).addComponent(VoteManager.class,
VoteManagerStd.class);
There are no call on the inject method
You can't build up properties, with successive as() invocations.
Post by cameleon104
This code work
inject.as(Characteristics.METHOD_INJECTION,
Characteristics.CACHE).addComponent(VoteManager.class,
VoteManagerStd.class);
The call on inject method is made
Obviously, the 'Characteristics.METHOD_INJECTION' is lost on the second call
to 'as' method.
There are many ways to do the same thing

1)

Properties[] CMI = new Properties[] {METHOD_INJECTION, CACHE}
pico.as(CMI).addComponent(VoteManager.class, VoteManagerStd.class);

2)

Mark yout components with @Cache at Class level for caching, and
@Inject above the method-injection-methods, the just do
pico.addComponent(VoteManager.class, VoteManagerStd.class);

3)

DefaultPicoContainer pico = new DefaultPicoContainer(new Caching());
pico.as(METHOD_INJECTION).addComponent(VoteManager.class,
VoteManagerStd.class);

4)

DefaultPicoContainer pico = new DefaultPicoContainer(new Caching());
pico.change(METHOD_INJECTION)
pico.addComponent(VoteManager.class, VoteManagerStd.class);
pico.change(CDI);
pico.addComponent(...
Post by cameleon104
Is it normal ? Is it a bug ?
Its expected - sorry.

- Paul

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

http://xircles.codehaus.org/manage_email
cameleon104
2008-04-09 12:51:40 UTC
Permalink
Hi,
Thanks a lot for the quick answer.
Most of solutions given fit perfectly to my need.
Picocontainer is really a very flexible tools.

Unless I had miss something, documentation didn't explain that I can't use
more than one 'as' function. It may be usefull to update javadoc with this
information ;-)
Post by Paul Hammant
Hi,
Post by cameleon104
Hi all,
To perform multiple type of injection, I use this code (I do not know if is
MutablePicoContainer pico = new DefaultPicoContainer();
MutablePicoContainer inject =
pico.as(Characteristics.METHOD_INJECTION);
MutablePicoContainer constructor = pico.as(Characteristics.CDI);
A problem appear when I try to use the 'as' method on 'inject' or
'constructor'
This code doesn't work
inject.as(Characteristics.CACHE).addComponent(VoteManager.class,
VoteManagerStd.class);
There are no call on the inject method
You can't build up properties, with successive as() invocations.
Post by cameleon104
This code work
inject.as(Characteristics.METHOD_INJECTION,
Characteristics.CACHE).addComponent(VoteManager.class,
VoteManagerStd.class);
The call on inject method is made
Obviously, the 'Characteristics.METHOD_INJECTION' is lost on the second call
to 'as' method.
There are many ways to do the same thing
1)
Properties[] CMI = new Properties[] {METHOD_INJECTION, CACHE}
pico.as(CMI).addComponent(VoteManager.class, VoteManagerStd.class);
2)
@Inject above the method-injection-methods, the just do
pico.addComponent(VoteManager.class, VoteManagerStd.class);
3)
DefaultPicoContainer pico = new DefaultPicoContainer(new Caching());
pico.as(METHOD_INJECTION).addComponent(VoteManager.class,
VoteManagerStd.class);
4)
DefaultPicoContainer pico = new DefaultPicoContainer(new Caching());
pico.change(METHOD_INJECTION)
pico.addComponent(VoteManager.class, VoteManagerStd.class);
pico.change(CDI);
pico.addComponent(...
Post by cameleon104
Is it normal ? Is it a bug ?
Its expected - sorry.
- Paul
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
View this message in context: http://www.nabble.com/call-to-%27as%27-method-erase-previous-Characteristics-tp16558740p16585346.html
Sent from the NanoContainer - PicoContainer - Users mailing list archive at Nabble.com.


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

http://xircles.codehaus.org/manage_email
Loading...