Ah, makes sense. I wonder if its possible to have an AbstractActiveBinder that recognizes @Singleton so that you could retain the type safety of the binding api while making as terse as possible. Is that something thats feasible as a contribution?
Zack
On May 28, 2014, at 11:46 AM, John Wells <john.wells_at_oracle.com> wrote:
> When you are using a binder none of the annotations are honored, instead all information comes from the binding itself. This allows people to have ghost annotations and ghost scopes and even different scopes from what is annotated on the class.
>
> If instead you want annotations to be automatically inspected I would recommend using addActiveDescriptor (https://hk2.java.net/2.3.0-b05/apidocs/org/glassfish/hk2/utilities/binding/AbstractBinder.html#addActiveDescriptor%28java.lang.Class%29) or something like ServiceLocatorUtilities.addClasses (https://hk2.java.net/2.3.0-b05/apidocs/org/glassfish/hk2/utilities/ServiceLocatorUtilities.html#addClasses%28org.glassfish.hk2.api.ServiceLocator,%20java.lang.Class...%29).
>
> Hope this helps...
>
> On 5/28/2014 1:29 PM, Zack Manning wrote:
>> When binding a singleton scoped class within an AbstractBinder, I notice that I always have to chain .in(Singleton.class) to every binding, regardless of if my class has @Singleton at the class level. Does HK2 actually pay attention to the singleton binding on the class? Or is this a bug?
>>
>>
.
>>
>> bindAsContract(SingleUseTokenCache.class).in(Singleton.class); //i wish this didnt need the latter
>>
>>
.
>>
>> @Singleton
>> public class SingleUseTokenCache {
>>
.
>>
>> Just some clarification would be much appreciated as it makes the configuration look muddier than it needs to be.
>>
>> Zack
>