Basically these two approaches into one:
Can Guice automatically create instances of different classes based on a parameter?
Guice injecting only some of the constructor
For example: User operation handlers are created with mapped and assisted injections, i.e. each needs some static bindings as well as an operation context that is created dynamically from a request.
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)
}
}