-
1. Re: Context injection for bean services
tfennelly Sep 1, 2011 5:51 AM (in response to kcbabo)I too am trying to think is there another approach.. the @ServiceContext annotation isn't too bad at all on its own, but something does feel strange (for me) about it in the context of the wider picture/usage... injecting a context instance for an Exchange that doesn't even exist yet (might never exist... depending on the logic). Just seems a bit funky to me.
-
2. Re: Context injection for bean services
kcbabo Sep 1, 2011 7:04 AM (in response to tfennelly)The only other two methods I could think of were:
(a) Create a wrapped type for injected references which has a getter for the service interface and the context. People that need to set/get context properties would inject this instead of the service interface.
@Inject @Reference private ServiceReference myService;
public interface ServiceReference { <T> T getInterface(); Context getContext(); }
(b) Add a ServiceContext class with a static method which is capable of querying the context for a reference:
@Inject @Reference private AnotherService anotherService; public void foo(String content) { Context context = ServiceContext.getContext(anotherService); context.setProperty("bleh", "meh"); anotherService.doSomething(...); }
The above is roughly the same implementation as the @Inject approach in my first post, but perhaps the presentation is a bit less funky for the user. :-)
-
3. Re: Context injection for bean services
tfennelly Sep 1, 2011 7:42 AM (in response to kcbabo)I was thinking along the lines of somehow registering a Context setting callback (for the service interface instance) at the time of invocation of the target service operation. The bean client proxy would call this back with the real Context instance associated with the real Exchange instance created by the proxy during the interface invocation. Not quite sure how that would look... need to think about it some more. Maybe something like...
public void foo(String content) { ServiceContext.registerSettingCallback(anotherService, new SettingCallback () { public void set(Context context) { context.setProperty("bleh", "meh"); context.setProperty("bleh", "meh"); } }); anotherService.doSomething(...); }
Yeah... thinking some more :-)
-
4. Re: Context injection for bean services
kcbabo Sep 1, 2011 9:34 AM (in response to tfennelly)Well, we both agree on what has to happened under the covers. :-) The callback method seems a bit verbose to me, but that's largely a matter of personal preference. I'm sure people will be more than happy to throw in their $0.02 on what looks best to them.