Adding component instances

View: New views
3 Messages — Rating Filter:   Alert me  

Adding component instances

by mihobson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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



Re: Adding component instances

by Paul Hammant-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

On Jun 11, 2009, at 9:20 AM, Mark Hobson wrote:

> 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
>
>


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

    http://xircles.codehaus.org/manage_email



Re: Adding component instances

by mihobson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

2009/6/11 Paul Hammant <paul@...>:

> 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
>
> On Jun 11, 2009, at 9:20 AM, Mark Hobson wrote:
>
>> 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
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>
>

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

    http://xircles.codehaus.org/manage_email