frjaeger220 / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Method interception on non-guice created objects #416

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Could it be possible to add the method interception functionality on non
Guice-created objects ?

I know this is not the primary goal of Guice, but it could be interesting
in the way that Guice can inject non Guice-created objects (with method
injectMembers), therefore we keep a parallel.

Here is how I see it:

new method: public <T> T Injector.intercept(T obj, MethodInterceptor...
interceptors);

1. intercept would check the class of obj then check in the interceptors
list if one matches
2. intercept would check if the class is valid according to limitations
3. intercept would create a new subclass of obj's class (if needed), like
it is currently done, with the delegate pattern in mind.
4. intercept would add optional interceptors given as parameters.
5. intercept returns a new instance of the newly created class, and
provides it with obj (if using the delegate pattern).

Original issue reported on code.google.com by ogregoire on 19 Aug 2009 at 12:16

GoogleCodeExporter commented 9 years ago
Guice is designed to work for objects created by Guice.  If you would like
interception of non-Guice created objects, please consider writing your own 
utilities
that take the proper interfaces.

Original comment by sberlin on 2 May 2010 at 12:31