users@hk2.java.net

binding a state machine

From: buko <buko_at_chiubarobot.com>
Date: Wed, 4 Jun 2014 22:27:50 -0400

Was trying to bind a state machine today where every state basically has a
reference to every other state. Eg:

class AbstractState {
 @Inject
 protected A a;

@Inject
 protected B b;

 @Inject
 protected C c;
}


class A extends AbstractState {
}

class B extends AbstractState {
}


class C extends AbstractState {
}

---
This sent hk2 into an infite loop between trying to create a state and
resolve its dependencies. Took a while to track down. (Some sort of loop
detection might be in order.)
The only way to get out of this was to @ProxyForSameScope and @UseProxy
everywhere. But this is less than desirable since (1) proxies have an
unknown overhead and (b)  considering the above are @PerLookup-scope by
default, why isn't it possible to resolve all the dependencies?
But it seems the code isn't anticipating the possibility of a class wanting
to inject an instance of itself.
Ideas...?