java - how to implement a global state with guice? -
i want create global state (data object, not service object).
i have created class mydataobject.
i want avoid regular global state,
but prefer using guice dependency injection.
however tutorials show how set di service object registration interface.
how can use guice injection need?
edit
i have tried:
public class appinjector extends abstractmodule {
@override protected void configure() { bind(e2eresult.class).toinstance(new e2eresult()); } }
with:
@test public void sendsearchrequest() throws exception { ... e2eresult = injector.getinstance(e2eresult.class); timerutils.settimeout(criticalblocktimeoutmilli); timerutils.startstopwatch(); ... long timeelapsed = timerutils.stopstopwatch(); e2eresult.runtime = timeelapsed; ... } and:
public static void main(string... args) throws classnotfoundexception, ioexception { injector injector = guice.createinjector(new appinjector()); result result = runtest(classandmethod); e2eresult e2eresult = injector.getinstance(e2eresult.class); } and yet saw in main without new long value.
to inject globalstate class should first create instance of it(set like) , bind class instance:
bind(globalstate.class) .toinstance(globalstate); globalstate can created , configured in "module", can read more here:
Comments
Post a Comment