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:

https://github.com/google/guice/wiki/gettingstarted


Comments

Popular posts from this blog

java - Unable to make sub reports with Jasper -

sql - The object name contains more than the maximum number of prefixes. The maximum is 2 -

scala - play framework: Modules were resolved with conflicting cross-version suffixes -