[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5682) Modify service infrastructure to leverage CDI annotations

Dan Allen (JIRA) noreply at atlassian.com
Wed Oct 20 15:30:47 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5682?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=38830#action_38830 ] 

Dan Allen commented on HHH-5682:
--------------------------------

You may not have to use CDI for this purpose. Even in Weld Extensions and Seam 3, we leverage the Java 6-style ServiceLoader pattern to specify an implementation of an SPI to use. See here for examples: http://github.com/weld/extensions/tree/master/impl/src/main/resources/META-INF/services/

It's true that an @Alternative would work in much the same way. The difference is that it would be activated in a beans.xml file rather than a META-INF/services descriptor. However, do note that alternatives have to be enabled per-module in which they are used. That's an important distinction.

Qualifiers are a way to identify an implementation by it's speciality. For instance, if you needed to get a classloader impl that followed the child-first delegation model, you might say "@Inject @ChildFirst ClassLoaderService", whereas if you needed the standard behavior you might do "@Inject @ParentChild ClassLoaderService" or just the default "@Inject ClassLoaderService". Qualified implementations are something the framework is going to be aware of. In contrast, an alternative (or standard ServiceLoader) resolve the implementation of specific interface (CDI alternatives actually enforce a single implementation). For instance, you could have alternatives for each qualified interface.

I would advise against using the term "named" when referring to services. Named means something specific in CDI. It's the mechanism of assigning a String-based name to a bean so it can be referenced outside of compiled Java code, such as in a view template. Instead, I would recommend the term "qualifier" or "alternative".

> Modify service infrastructure to leverage CDI annotations
> ---------------------------------------------------------
>
>                 Key: HHH-5682
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5682
>             Project: Hibernate Core
>          Issue Type: Task
>          Components: core
>            Reporter: Steve Ebersole
>            Assignee: Gail Badner
>             Fix For: 4.0.0.Alpha1
>
>
> Specific annotations to look at:
> @Inject
> @Alternative
> @Produces
> @Disposes
> Also need to investigate the following requirements not really covered in CDI:
> # Services are always "named" by the {{service role}} they fulfill.  All {{service implementors}} (the class) are simply @Alternative impls of that {{service role}} contract.  How to express this in CDI (the {{service role}} == name part)?
> # Optional dependency
> ## Custom CDI qualifier
> ## CDI {{Instance<T>}}
> ## {{ServiceRegistryAware}} (though TBH, perhaps that should even be a normal injection)

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

        


More information about the hibernate-issues mailing list