Re: [picocontainer-dev] FactoryAdapter patch
Paul Hammant <[email protected]>
| Newsgroups | gmane.comp.java.picocontainer.devel |
|---|---|
| Message-ID | <[email protected]> |
So take a look at http://svn.codehaus.org/picocontainer/java/2.x/trunk/pico/container/src/test/org/picocontainer/DefaultPicoContainerTestCase.java
Everything from Swede on down, is new in the last few days.
These two demonstrate the usage of the new ComponentAdapter method
that references the type you're injecting into.
testThatComponentCanHaveAProvidedDependency()
testThatComponentCanHaveAProvidedDependencyViaConstructor()
These two might be more like what Jörg is suggesting, in that they are
behaviors that happen after injection. ...
testThatComponentCanHaveAProvidedDependencyViaDecoratorBehavior()
testThatComponentCanHaveAProvidedDependencyViaFieldDecoratorBehavior()
It is entirely possible that what I committed on Weds morning was
wrong. "Just because we can does not mean we should".
The fellow on the user list (Peter Karich) might be just as pleased
with the behavior/decorator route.
Thoughts?
- Paul
On Apr 23, 2008, at 12:54 PM, Paul Hammant wrote:
> Is this what you mean Jörg ? ....
>
> public class LoggingDecorator extends AbstractBehaviorFactory {
> public <T> ComponentAdapter<T> createComponentAdapter(
> ComponentMonitor componentMonitor,
> LifecycleStrategy lifecycleStrategy,
> Properties componentProperties, Object componentKey,
> Class<T> componentImplementation, Parameter... parameters)
> throws PicoCompositionException {
> ComponentAdapter componentAdapter =
> super.createComponentAdapter(componentMonitor, lifecycleStrategy,
> componentProperties
> , componentKey, componentImplementation, parameters);
> return new LoggingDecorated(componentAdapter);
> }
> }
>
> public class LoggingDecorated<T> extends AbstractBehavior<T> {
> public LoggingDecorated(ComponentAdapter<T> delegate) {
> super(delegate);
> }
> public T getComponentInstance(final PicoContainer container, Type
> into) throws PicoCompositionException {
> Object inst = getDelegate().getComponentInstance(container,
> into)
>
> inst
> .getClass
> ().getField("log").setValue(LogFactory.getLogger(inst.getClass()));
> return inst;
> }
> }
>
> Or a design that looked for more than the field, and called a setter
> from an interface ?
>
> - Paul
>
> On Apr 23, 2008, at 9:29 AM, Paul Hammant wrote:
>
>> Oh sorry, didn't see this before the commit Jörg - I'll answer
>> shortly.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>