users@hk2.java.net

Strange Behavior around Factories

From: buko <buko_at_chiubarobot.com>
Date: Thu, 1 Aug 2013 08:26:38 -0400

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?