@Uses in service mixin

7 views
Skip to first unread message

michaelp

unread,
Dec 17, 2014, 5:49:24 AM12/17/14
to qi4j...@googlegroups.com
Hi guys, 

Is it proper with Qi4j to have a @Uses annotation in a Service mixin, and if yes, how can one inject the object into the mixin instance at runtime?
More specifically, here's an example sketch:

@Mixins{AbcService.Mixin.class}
interface AbcService implements Abc, ServiceComposite {

    ...

    class Mixin implements Abc {
        
        @Uses
        SomeInterface obj;
        
        ...
    }
}

Then:

ServiceReference<AbcService> serviceRef = module.findService(AbsService.class);
AbcService abcService = serviceRef.get();

At this point, how can I inject a SomeInterface object into the abcService instance?
TransientBuilder.use() is not applicable to this case, or is it in some way?

Best regards,
Michael


Niclas Hedhman

unread,
Dec 17, 2014, 9:36:04 AM12/17/14
to michaelp, qi4j...@googlegroups.com
Well, the reason use() didn't exist in Services is because they are not really that transient. They are declared in bootstrapping and activated on usage, and no injection point as with the builders.

I think you could declare Imported Services instead of regular services to accomplish a similar result. Sometimes Meta Info can work, since services are singletons (per declaration).

If you explained the usecase, perhaps I could give better ideas (or even find that we need a new feature).


Cheers

--
You received this message because you are subscribed to the Google Groups "qi4j-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qi4j-dev+u...@googlegroups.com.
To post to this group, send email to qi4j...@googlegroups.com.
Visit this group at http://groups.google.com/group/qi4j-dev.
For more options, visit https://groups.google.com/d/optout.


--
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java
Reply all
Reply to author
Forward
0 new messages