[ 
http://issues.ops4j.org/browse/QI-266?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13572#action_13572
 ] 

Niclas Hedhman commented on QI-266:
-----------------------------------

Rickard wrote on mailing list;

The @Service injection has so far only been able to specify the type of the 
service to be injected. If any other type of qualification had to be done it 
was to be done through a ServiceSelector. This works, but for common cases it 
would be more convenient to use annotations to do this filtering. I have now 
updated the ServiceSelector API quite a bit, and at the same time implemented 
annotation support to perform this qualification.

Example:
@Service @Tagged("sometag") MyService service;

This will only inject instances of MyService that have been tagged with 
"sometag". If none exist an exception will occur at injection time since it is 
not optional.

It also works with iterables:
@Service @Tagged("sometag") Iterable<MyService> services;

The qualification will be evaluated upon each call to iterator(), and since the 
qualifier has access to a ServiceReference, which contains the isActive() 
method, it can even provide some dynamicity. Example:

@Service @Active Iterable<SomeImportedService> importedServices;

Let's say these SomeImportedService are only sometimes available. Then whenever 
iterator() is called the @Active tag can kick in and filter out those whose 
ServiceReference.isActive() returns false.

See tests and API for more examples, and how to implement your own qualifiers. 
Standard ones I've defined in the API are:
@Tagged
@IdentifiedBy
@Active

> Introduction of Service Qualifier API
> -------------------------------------
>
>                 Key: QI-266
>                 URL: http://issues.ops4j.org/browse/QI-266
>             Project: Qi4j
>          Issue Type: New Feature
>          Components: API
>            Reporter: Niclas Hedhman
>            Assignee: Rickard Öberg
>             Fix For: 1.2
>
>
> The @Service injection has so far only been able to specify the type of the 
> service to be injected. If any other type of qualification had to be done it 
> was to be done through a ServiceSelector. This works, but for common cases it 
> would be more convenient to use annotations to do this filtering.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.ops4j.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to