Discussion:
Injection to already instantiated component instance
Marcin Waldowski
2008-10-18 12:46:25 UTC
Permalink
Hello.

Is there an easy way to inject dependencies to already instantiated
object (setter or annotated field injection)?

I need to use some api which give me a chance to do something with
component after instantiation. The idea is to use PicoContainer to
inject dependensies using setter or annotated field injection to already
instantiated object.

It looks like this:

public class PicoInjectorComponentListener
implements ComponenInstantiationtListener {

/**
* @see ComponenInstantiationtListener#afterInstantiation(Object)
*/
public void afterInstantiation(Object newComponent) {

// TODO:
// inserting dependencies to newComponent
// using PicoContainer API

}
}

Unfortunately I cannot change existing api to use PicoContainer in a
standard way.

I found that AnnotatedFieldInjector and SetterInjector have a method
decorateComponentInstance but I cannot figure out how to use it. Can I
ask for any hint?

Regards,
Marcin Waldowski




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

http://xircles.codehaus.org/manage_email
Paul Hammant
2008-10-18 16:37:09 UTC
Permalink
Hi Martin,

Yes it's possible. I'll write you some example code. But first, tell
me ...

void afterInstantiation(Object newComponent)

... is the component type really Object rather that something more
fine grained ?

Regards,

- Paul
Post by Marcin Waldowski
Hello.
Is there an easy way to inject dependencies to already instantiated
object (setter or annotated field injection)?
I need to use some api which give me a chance to do something with
component after instantiation. The idea is to use PicoContainer to
inject dependensies using setter or annotated field injection to already
instantiated object.
public class PicoInjectorComponentListener
implements ComponenInstantiationtListener {
/**
*/
public void afterInstantiation(Object newComponent) {
// inserting dependencies to newComponent
// using PicoContainer API
}
}
Unfortunately I cannot change existing api to use PicoContainer in a
standard way.
I found that AnnotatedFieldInjector and SetterInjector have a method
decorateComponentInstance but I cannot figure out how to use it. Can I
ask for any hint?
Regards,
Marcin Waldowski
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Marcin Waldowski
2008-10-18 20:40:49 UTC
Permalink
Paul, thanks for the answer.

No, the component type is not Object. As a matter of fact I was thinking
about using Apache Wicket with PicoContainer. The true interface you
could find here:

http://wicket.apache.org/docs/wicket-1.3.2/wicket/apidocs/org/apache/wicket/application/IComponentInstantiationListener.html

Regards,
Marcin
Post by Paul Hammant
Hi Martin,
Yes it's possible. I'll write you some example code. But first, tell
me ...
void afterInstantiation(Object newComponent)
... is the component type really Object rather that something more
fine grained ?
Regards,
- Paul
Post by Marcin Waldowski
Hello.
Is there an easy way to inject dependencies to already instantiated
object (setter or annotated field injection)?
I need to use some api which give me a chance to do something with
component after instantiation. The idea is to use PicoContainer to
inject dependensies using setter or annotated field injection to already
instantiated object.
public class PicoInjectorComponentListener
implements ComponenInstantiationtListener {
/**
*/
public void afterInstantiation(Object newComponent) {
// inserting dependencies to newComponent
// using PicoContainer API
}
}
Unfortunately I cannot change existing api to use PicoContainer in a
standard way.
I found that AnnotatedFieldInjector and SetterInjector have a method
decorateComponentInstance but I cannot figure out how to use it. Can I
ask for any hint?
Regards,
Marcin Waldowski
---------------------------------------------------------------------
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
Paul Hammant
2008-10-18 20:57:07 UTC
Permalink
Marcin,

Take a look at ...

http://svn.codehaus.org/picocontainer/java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/ReinjectionTestCase.java

For the component instance you want to inject into some time after
instantiation, as long as the return type to the method in question is
void and parameters for the arguments are strongly typed, it'll be fine.

I'll be making a change soon (PicoContainer 2.7??) though that will be
more meaningful for reinjection to components where the method does
return something. The web frameworks Waffle does this too for
arbitrary methods.

Wicket is something that we'd like to add the set of example apps : http://svn.codehaus.org/picocontainer/java/2.x/trunk/web/examples/
Give us some pointers on where to start :-)

- Paul
Post by Marcin Waldowski
Paul, thanks for the answer.
No, the component type is not Object. As a matter of fact I was thinking
about using Apache Wicket with PicoContainer. The true interface you
http://wicket.apache.org/docs/wicket-1.3.2/wicket/apidocs/org/apache/wicket/application/IComponentInstantiationListener.html
Regards,
Marcin
Post by Paul Hammant
Hi Martin,
Yes it's possible. I'll write you some example code. But first, tell
me ...
void afterInstantiation(Object newComponent)
... is the component type really Object rather that something more
fine grained ?
Regards,
- Paul
Post by Marcin Waldowski
Hello.
Is there an easy way to inject dependencies to already instantiated
object (setter or annotated field injection)?
I need to use some api which give me a chance to do something with
component after instantiation. The idea is to use PicoContainer to
inject dependensies using setter or annotated field injection to already
instantiated object.
public class PicoInjectorComponentListener
implements ComponenInstantiationtListener {
/**
*/
public void afterInstantiation(Object newComponent) {
// inserting dependencies to newComponent
// using PicoContainer API
}
}
Unfortunately I cannot change existing api to use PicoContainer in a
standard way.
I found that AnnotatedFieldInjector and SetterInjector have a method
decorateComponentInstance but I cannot figure out how to use it. Can I
ask for any hint?
Regards,
Marcin Waldowski
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
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
Marcin Waldowski
2008-10-19 20:21:17 UTC
Permalink
Paul, thanks for informations.

It looks like there are some subprojects in wicket source which are
related do IOC.

http://svn.apache.org/repos/asf/wicket/releases/wicket-1.3.5/jdk-1.4/wicket-ioc
http://svn.apache.org/repos/asf/wicket/releases/wicket-1.3.5/jdk-1.5/wicket-guice

I will look at this code and check how the things are done. After that I
will hopefully know if informations from you are sufficient to implement
Wicket - PicoContainer integration.

Regards,
Marcin
Post by Paul Hammant
Marcin,
Take a look at ...
http://svn.codehaus.org/picocontainer/java/2.x/trunk/pico/container/src/test/org/picocontainer/injectors/ReinjectionTestCase.java
For the component instance you want to inject into some time after
instantiation, as long as the return type to the method in question is
void and parameters for the arguments are strongly typed, it'll be fine.
I'll be making a change soon (PicoContainer 2.7??) though that will be
more meaningful for reinjection to components where the method does
return something. The web frameworks Waffle does this too for
arbitrary methods.
Wicket is something that we'd like to add the set of example apps : http://svn.codehaus.org/picocontainer/java/2.x/trunk/web/examples/
Give us some pointers on where to start :-)
- Paul
Post by Marcin Waldowski
Paul, thanks for the answer.
No, the component type is not Object. As a matter of fact I was thinking
about using Apache Wicket with PicoContainer. The true interface you
http://wicket.apache.org/docs/wicket-1.3.2/wicket/apidocs/org/apache/wicket/application/IComponentInstantiationListener.html
Regards,
Marcin
Post by Paul Hammant
Hi Martin,
Yes it's possible. I'll write you some example code. But first, tell
me ...
void afterInstantiation(Object newComponent)
... is the component type really Object rather that something more
fine grained ?
Regards,
- Paul
Post by Marcin Waldowski
Hello.
Is there an easy way to inject dependencies to already instantiated
object (setter or annotated field injection)?
I need to use some api which give me a chance to do something with
component after instantiation. The idea is to use PicoContainer to
inject dependensies using setter or annotated field injection to already
instantiated object.
public class PicoInjectorComponentListener
implements ComponenInstantiationtListener {
/**
*/
public void afterInstantiation(Object newComponent) {
// inserting dependencies to newComponent
// using PicoContainer API
}
}
Unfortunately I cannot change existing api to use PicoContainer in a
standard way.
I found that AnnotatedFieldInjector and SetterInjector have a method
decorateComponentInstance but I cannot figure out how to use it. Can I
ask for any hint?
Regards,
Marcin Waldowski
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
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

Continue reading on narkive:
Search results for 'Injection to already instantiated component instance' (Questions and Answers)
5
replies
can i get question answer of asp.net ?
started 2006-10-11 00:02:47 UTC
software
Loading...