I'm struggling to come up with a solution where I can use Dagger and Lambda. The main issue seems that dependency injection happens in the constructor, while you have to provide at least one 0-arg-constructor in Lambda. How can I overcome this?
I'm struggling to come up with a solution where I can use Dagger and Lambda. The main issue seems that dependency injection happens in the constructor, while you have to provide at least one 0-arg-constructor in Lambda. How can I overcome this?
The solution I've come up to (and blogged about) is to make your zero-args constructor retrieve the constructed Dagger configuration i.e.:
public Handler() {
this(DaggerConfig.create().serviceLayer());
}
/* test only */ Handler(ServiceLayer service) {
this.service = service;
}
No need to provide 0-arg-constructor. Try lambda event and extend request handler. guice, spring resolve the dependency on runtime, which might increase your cold start time. On the other hand, dagger2 resolves dependency on compile time. For more details: https://www.youtube.com/watch?v=plK0zyRLIP8