1
基本上這兩種方法爲一個:是否可以將Guice的輔助和貼圖注射結合起來?
Can Guice automatically create instances of different classes based on a parameter?
Guice injecting only some of the constructor
例如: 用戶操作處理程序以映射和輔助注射創建的,即,每個需要一些靜態綁定以及操作上下文這是從請求動態創建的。
class OpHandler { void handle()... }
class SendHandler extends OpHandler {
public SendHandler(DAL dal, SendContext context) { ... }
}
class ReceiveHandler extends OpHandler {
public ReceiveHandler(DAL dal, ReceiveContext context) { ... }
}
servlet:
onGet() {
op = resolveOp();
switch (op) {
SEND: create SendContext and pass it somehow to ioc.getInstance(SendHandler.class)
RECEIVE: create ReceiveContext and pass it somehow to ioc.getInstance(ReceiveHandler.class)
}
}
感謝您的代碼。我理解輔助注射的概念,但我不認爲這是我所問的。在我的帖子中提到的例子中,我沒有看到映射綁定。這裏是鏈接:http://stackoverflow.com/questions/17669413/can-guice-automatically-create-instances-of-different-classes-based-on-a-paramet。 – Schultz9999
*上下文是你需要設置的東西嗎? –