5
考慮一個匕首模塊:回溯上匕首。再加()不完整的父
@Module(library = true, complete = false)
public static class Module {
@Provides
public Contextualized providesContextualized(Context ctx) {
return new Contextualized(ctx.getUsername());
}
// ... and many more such provides.
}
上下文是對象可被連接到例如不能在啓動時被稱爲HTTP會話 ,當一個人通常會創建一個 圖:
@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; }
};
}
}
由於模塊是足夠長,這似乎使 意義首先創建一個圖表,模塊:
ObjectGraph baseline = ObjectGraph.create(new Module());
,然後,在處理特定請求,創建一個獨特的圖形 ,使圖形完整:
ObjectGraph withContext = baseline.plus(new ContextModule("killroy"));
然而,。再加上()似乎認爲繼承圖是完全圖:
java.lang.IllegalStateException: Errors creating object graph:
Context could not be bound with key Context required by class PlusExample$Module
at dagger.internal.ThrowingErrorHandler.handleErrors(ThrowingErrorHandler.java:34)
at dagger.internal.Linker.linkRequested(Linker.java:182)
at dagger.internal.Linker.linkAll(Linker.java:109)
at dagger.ObjectGraph$DaggerObjectGraph.linkEverything(ObjectGraph.java:244)
at dagger.ObjectGraph$DaggerObjectGraph.plus(ObjectGraph.java:203)
at PlusExample.plusFailsOnIncompleteModule(PlusExample.java:46)
難道我誤解了。再加上()做或這是 匕首的限制?有沒有其他直接的方法可以將 用戶延遲引入圖表中? (這將是煩人的,如果每一個模塊提供 將不得不從一個ThreadLocal或 一些這樣的查找用戶。)