2009/3/31 [email protected] <[email protected]>:
>
>
>
> On Mar 31, 1:20 pm, James Strachan <[email protected]> wrote:
>> Cool. How about I try hack up a little prototype of JSR 250 in
>> guiceyfruit using the new injectable type listener - I'll point you at
>> the various little helper/facade objects I figure out and then if you
>> want them I can submit them as a patch to Guice otherwise we can leave
>> them as an extension module? To be honest its probably only gonna be a
>> few little helper classes; but then their use might not be that
>> widespread to be in the core of Guice - I'll let you decide when I've
>> figured something out. I'm easy either way really.
>
> Excellent. When it's all done we'll take a look and decide if best
> fits in Guice's extensions/ or in Guiceyfruit. Thanks James.

OK I've got the @Resource injection and @PostConstruct working fine
now. (Work on @PreDestroy is currently pending - that might need a
patch or two on Guice yet - not sure).

There's not that much code used to implement this; so feel free to
lift whatever you like back into Guice.

Mostly the heavily lifting is done by 2 main helper methods on a base
AbstractModule...
http://code.google.com/p/guiceyfruit/source/browse/trunk/guiceyfruit-core/src/main/java/org/guiceyfruit/support/GuiceyFruitModule.java

this provides basically 2 flavours of helper methods:

* bindAnnotationInjector(): binds an annotation with an
AnnotationMemberProvider (which is just like a Provider but its given
the annotation instance and member as parameters as well).
http://code.google.com/p/guiceyfruit/source/browse/trunk/guiceyfruit-core/src/main/java/org/guiceyfruit/support/AnnotationMemberProvider.java

The first parameter is the annotation and the second is a key/type of
an annotationMemberProvider (so Guice can inject the instance). This
method is used to inject some arbitrary value into an annotated field
or method with a single parameter using a custom strategy to create
the value.

* bindMethodHandler(): binds an annotation with a MethodHandler which
allows an annotated method to be processed using a custom method
handling strategy.
http://code.google.com/p/guiceyfruit/source/browse/trunk/guiceyfruit-core/src/main/java/org/guiceyfruit/support/MethodHandler.java

This could be a post commit style hook; but can also be for other
uses, like binding a method to some kind of event raising mechanism;
or in the case of Apache Camel to subscribe to some message bus or
other network protocol and bind the incoming messages to the method. A
POJO version of message driven beans if you will.


The second parameter in both methods can be specified as an instance,
a key or type. If its the latter 2 options then guice does the
injection. To simplify the code of the 3 versions of each method, I
created a little EncounterProvider helper class
http://code.google.com/p/guiceyfruit/source/browse/trunk/guiceyfruit-core/src/main/java/org/guiceyfruit/support/EncounterProvider.java
who's job it is to create a Provider of the strategy based on an
encounter and whatever the key is (Key or Class etc)

I'm not totally sold on the name "MethodHandler" its a bit vague :).
Its basically useful for either post construct callbacks or for event
binding type stuff.


All in all not very much code; so it could well move into the core of
Guice if you like.

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to