users@hk2.java.net

Re: Strange Behavior around Factories

From: John Wells <john.wells_at_oracle.com>
Date: Sun, 04 Aug 2013 09:58:08 -0400

I have found and fixed this problem. There were actually a few problems
around proxying that I have fixed, in particular proxying was almost
always turned off even if the scope was a proxying scope.

This will be in the next release of hk2, which would be 2.2.0-b15 (or
higher).

On 8/1/2013 11:41 AM, John Wells wrote:
> I will write a test to see if I see the same behavior. If so I'll
> enter a Jira. Or, if you have some simple code that demonstrates this
> you could add a Jira as well.
>
> On 8/1/2013 8:26 AM, buko wrote:
>> Seeing strange behavior around factories that's not readily explained
>> by any of the javadoc.
>>
>> > bindFactory(new ClientHolder()).to(Client.class).proxy(true);
>>
>> In this case, the 'proxy(true)' is ignored. Any other service that
>> injects Client will immediately call the provide() method on
>> ClientHolder and this will raise an exception indicating no Client is
>> available.
>>
>> > bindFactory(ClientHolder.class).to(Client.class).proxy(true);
>>
>> In this case proxy(true) is respected. Other services will be
>> injected with a proxy of the Client.
>>
>> But now, no other class can inject or get a reference the
>> ClientHolder class and initialize the Client object. Result is that
>> eventually it gets new'd up when somebody uses the proxy and an
>> exception is thrown.
>>
>> Question: why isn't proxy() respected in the first case when a
>> factory instance is bound?
>