I'm working on some Java Jersey stuff and would like to do the following;
I've got a class called SerialSubject:
public class SerialSubject{
private final SomeDatabase someDatabase;
@Inject
public SerialSubject(SomeDatabase someDatabase){
this.someDatabase = someDatabase;
initializeSerial();
}
InitializeSerial(){
SerialConfig config = SomeDatabase.getConfig();
//Open a Serial connection using this config
}
}
I'm binding this class using an AbstractBinder and register it to my ResourceConfig as per usual.
bind(SerialSubject.class).to(SerialSubject.class).in(Singleton.class)
All good and well, the dependency is resolved when requested by a resource and the serial connection is opened.
Now the caveat: I want to open the Serial connection at startup time. Is there any way to instantiate the class immediately? Constructing it manually won't do, as the database(which is already bound to ioc) is needed to retrieve the configuration.