The ManagedContext approach looks good to me. The Guice version would look something like:
@Singleton
public class GuiceManagedContext implements ManagedContext {
final Injector injector;
@Inject GuiceManagedContext(Injector injector) {
this.injector = injector;
}
@Inject void addToConfig(Config config) {
config.setManagedContext(this);
}
public void initialize(Object obj) {
injector.injectMembers(obj);
}
}
This assumes the Config itself is bound somewhere, and that GuiceManagedContext is bound as an eager singleton.
Because I'm using a custom DataSerializable base class (using Jackson's binary Smile format!), I already have the opportunity to do member injection there.
--tim