Dagger with Java AWS Lambda?

Viewed 4161

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?

2 Answers

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;
}
Related