-
-
Notifications
You must be signed in to change notification settings - Fork 981
#2257 Adding abstract class mappers with defined constructor #3546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
#2257 Adding abstract class mappers with defined constructor #3546
Conversation
For spring mappers you can inject components by constructor when it is defined
Thanks for the PR @TheAndreyy. From what I could see this only works for spring. In order for us to be able to accept this we would need to have full support for the rest of the component models as well (for those where this is possible). Is this something that you can work on to finish the PR? |
Hey @filiphr, thank for the review. Yes, I'd be happy to implement this. Now it only works for Spring as you've designed it in this comment. As I'm monstly fimiliar with Spring, I have to ask you for more requirements regarding other component models constructors. For example if I add this for "default" ComponentModel, getting Mapper instance like this |
In that comment I was saying that it would be easy for Spring, but that we should make it work for all 😄.
For the non default ones, I would say similar to Spring. For the default component model we could do something similar like we are doing for the fields. i.e. if it is a mapper use |
@filiphr Ok, I'll add it to other component models. I'm not sure, I understand correctly your solution. You mean to create additional no-args-constructor that supplies super constructor with empty members, similar like in public MapperWithCanonicalConstructor() {
super( field1Type.newInstance(), field2Type.newInstance() );
}
What do you mean by that? |
Not sure if we are talking about the default component model now. If it is about the default I mean to generate something like: public MyCustomMapperImpl() {
super( Mappers.getMapper(MyOtherMapper.class), new MyUtils() );
} basically we need to do exactly what we are doing when
oops, I meant to say "When calling the supper", not idea why I said "support" |
…el requirements
@filiphr I've added changes as you requested. I've tried to satisfy requirements of a constructor for all component models, but not all have tests with constructor injection so I couldn't copy them ;) Waiting for your code suggestions! |
Hey @filiphr, hope you had good rest during Easter break. If you find some time for code review I'd be grateful 😄 |
...truct/ap/test/canonicalconstructor/defaultcomponentmodel/UserCanonicalConstructorMapper.java
Show resolved
Hide resolved
Sorry @TheAndreyy, I've been a bit busy before and after the Easter break and didn't have much time to review this. I'll try to check it out and provide feedback to you asap |
Hi, long time no see ;) I've added support for Thanks for pointing this out @zyberzebra, I haven't used it before. In my opinion now it works more elegant - see test Waiting for review, I'm counting on you @filiphr that you find some time :) |
Hi @filiphr, I see I've missed to check code formatting, now pipeline should pass. Waiting for code review suggestions 😄 |
For spring mappers you can inject components by constructor when it is defined, mapper implementation will call it's super constructor.
Adding calling super canonical costructor only for Spring mappers as decided in referenced issue (#2257) by project maintainers