mapstruct icon indicating copy to clipboard operation
mapstruct copied to clipboard

Added new componentModel to improve Dagger2 support

Open leonardortlima opened this issue 2 years ago • 6 comments

Added a new componentModel for Dagger2, as suggested in #1617 and #2337

Dagger2 is mostly compatible with the existing jsr330 componentModel, but it has 2 issues:

  1. For constructor injection, a constructor annotated with @Inject should always be present, even if the constructor is empty
  2. For field injection, it requires the fields to be package private (no access modifiers)

Issue 1 should be fixed by the current state of this PR Issue 2 would involve changing more stuff, and I'm not sure if you'd be interested in supporting it, since constructor injection is preferred with Dagger

Also, I'd like some help fixing the integration tests, if possible. I'm having trouble making both dagger and mapstruct annotation processing work during testing

leonardortlima avatar Jul 16 '21 15:07 leonardortlima

Thanks for the feedback @filiphr.

I will try to implement field injection too

leonardortlima avatar Jul 17 '21 12:07 leonardortlima

can you support custom scope annotations while doing this?

facboy avatar Oct 28 '21 16:10 facboy

@facboy what do you mean by "can you support custom scope annotations while doing this?"

filiphr avatar Oct 30 '21 11:10 filiphr

you can annotate dagger injectables with any scope, it doesn't have to be Singleton. mapstruct should support specifying the scope annotation for the generated mapper.

facboy avatar Oct 31 '21 11:10 facboy

Thanks for the explanation @facboy. The initial support will not take that into consideration. The other dependency injection frameworks have such scope functionality, but we do not support it currently.

That is more related to something like #1427, #990 and #2041.

filiphr avatar Oct 31 '21 11:10 filiphr

Any updates on this?

wonsuc avatar May 13 '22 02:05 wonsuc

This should also change MapStruct mappers to be marked @Reusable instead of @Singleton

Rubydesic avatar Nov 04 '22 01:11 Rubydesic