Discussion:
Adding component instances
Mark Hobson
2009-06-11 14:20:29 UTC
Permalink
Hi there,

Is there a more explicit way of registering a component instance to a
container that I'm missing, other than the usual
MutablePicoContainer.addComponent method? A problem arises when you
actually want to register a Class instance and DefaultPicoContainer
treats it as an implementation. I can't see a way of achieving this
with properties.

Perhaps addConfig could be generalised further into addInstance for
these purposes? Of course, using addAdapter with an InstanceAdapter
works but you lose the lifecycle strategy and component monitor.

Cheers,

Mark

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

http://xircles.codehaus.org/manage_email
Paul Hammant
2009-06-11 16:29:46 UTC
Permalink
See org.picocontainer.classname.ClassName.

Obviously its not quite what you want, but we could have a similar
wrapper 'ClassDef' that would be suggest to Pico that its payload is
directly injectable rather than candidate for turning into an instance.

Thoughts?

Regards,

- Paul
Post by Mark Hobson
Hi there,
Is there a more explicit way of registering a component instance to a
container that I'm missing, other than the usual
MutablePicoContainer.addComponent method? A problem arises when you
actually want to register a Class instance and DefaultPicoContainer
treats it as an implementation. I can't see a way of achieving this
with properties.
Perhaps addConfig could be generalised further into addInstance for
these purposes? Of course, using addAdapter with an InstanceAdapter
works but you lose the lifecycle strategy and component monitor.
Cheers,
Mark
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Mark Hobson
2009-06-12 09:13:13 UTC
Permalink
That would work, although it seems like a bit of a convoluted solution
to workaround addComponent's interpretation.

Ideally we'd have addComponent(Object, Class) and addInstance(Object,
Object), which would supersede addConfig, but that's quite a breaking
change. Perhaps relax addConfig to take an Object key, or even
overload addComponent with a Class implementation so that:

- addComponent(Object, Object) always registers the component as an instance
- addComponent(Object, Class) always registers the component as an
implementation

So a class instance could be registered with addComponent(key,
(Object) MyClass.class). It's a bit magical though, and would require
clients to be recompiled.

Mark
Post by Paul Hammant
See org.picocontainer.classname.ClassName.
Obviously its not quite what you want, but we could have a similar wrapper
'ClassDef' that would be suggest to Pico that its payload is directly
injectable rather than candidate for turning into an instance.
Thoughts?
Regards,
- Paul
Post by Mark Hobson
Hi there,
Is there a more explicit way of registering a component instance to a
container that I'm missing, other than the usual
MutablePicoContainer.addComponent method?  A problem arises when you
actually want to register a Class instance and DefaultPicoContainer
treats it as an implementation.  I can't see a way of achieving this
with properties.
Perhaps addConfig could be generalised further into addInstance for
these purposes?  Of course, using addAdapter with an InstanceAdapter
works but you lose the lifecycle strategy and component monitor.
Cheers,
Mark
---------------------------------------------------------------------
  http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
  http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...