Updates:
Owner: sberlin
Comment #16 on issue 78 by sberlin: Support Provision Interception /
Construction Interception
http://code.google.com/p/google-guice/issues/detail?id=78
Attached is a proof-of-concept (rough around the edges, needs more tests,
etc.. but completely working AFAICT) patch that adds provision listening
for normal (constructor) bindings & provider bindings. The API is:
bindListener(Matcher<? super Key<?>>, ProvisionListener)
ProvisionListener {
<T> void onProvision(ProvisionInvocation<T> invocation)
ProvisionInvocation<T> {
Key<T> getKey()
T provision();
}
}
The idea is similar to TypeListeners, except with less overheard & it can
apply to _all_ bindings that require provisioning, not just injectable ones
(which excluded Provider bindings). It also lets you match based on Key
rather than TypeLiteral.
ProvisionListener acts similar to a MethodInterceptor, except the user is
unable to change any of the arguments or return value. If the
user "forgets" to call provision(), it is done automatically. Exceptions
handling is a little complicated, but it basically follows a rule of:
* If an exception is thrown while performing the provision, the listener
will see it as ProvisionException during the provision() call. Regardless
of what the user does to the exception (including if they supress it,
manipulate it, or throw another exception type afterwards), Guice will
rethrow the original exception.
* If a listener throws an exception, Guice will rethrow that exception
within a ProvisionException.
Attachments:
provision-listeners.txt 50.9 KB
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.