java - Traceback on Dagger .plus() on incomplete parent -
consider dagger module:
@module(library = true, complete = false) public static class module { @provides public contextualized providescontextualized(context ctx) { return new contextualized(ctx.getusername()); } // ... , many more such provides. }
context object may connected e.g. http session cannot known @ startup, when 1 create graph:
@module(library = true, complete = false) public static class contextmodule { private final string username; public contextmodule(string username) { this.username = username; } @provides public context providescontext() { return new context() { public string getusername() { return username; } }; } }
given module sufficiently long, seem make sense first create graph module:
objectgraph baseline = objectgraph.create(new module());
and then, on processing particular request, create unique graph makes graph complete:
objectgraph withcontext = baseline.plus(new contextmodule("killroy"));
however, .plus() seems assume inherited graph complete:
java.lang.illegalstateexception: errors creating object graph: context not bound key context required class plusexample$module @ dagger.internal.throwingerrorhandler.handleerrors(throwingerrorhandler.java:34) @ dagger.internal.linker.linkrequested(linker.java:182) @ dagger.internal.linker.linkall(linker.java:109) @ dagger.objectgraph$daggerobjectgraph.linkeverything(objectgraph.java:244) @ dagger.objectgraph$daggerobjectgraph.plus(objectgraph.java:203) @ plusexample.plusfailsonincompletemodule(plusexample.java:46)
have misunderstood .plus() or limitation in dagger? there other straightforward way introduce user late graph? (it annoying if each provide in module have user threadlocal or such.)
looks answer question: https://github.com/square/dagger/issues/384
hope helps!
Comments
Post a Comment