Skip to content

Conversation

giulong
Copy link
Contributor

@giulong giulong commented Jul 13, 2025

After a quite deep analysis on #4218, I ended up implementing what was also suggested in this comment.

This way, when there are both creator properties and fields with the same injection, we mark the annotated field to be ignored when creating the corresponding injectable.
We ignore fields instead of constructor properties considering that constructor injection happens before field injection, and users may need the injected value in the constructor to do any additional logic on their side.

This seems to solve #2678 as well.

Waiting for feedbacks and improvements

…sponding injected constructor parameter is available

for (Map.Entry<Object, AnnotatedMember> entry : raw.entrySet()) {
AnnotatedMember m = entry.getValue();
if (m.isIgnoreInjection()) {
Copy link
Contributor Author

@giulong giulong Jul 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid creating a redundant ValueInjector for fields whose injection was already performed via constructor properties.

@cowtowncoder
Copy link
Member

cowtowncoder commented Jul 16, 2025

I like the concept, although would prefer not adding configuring state in AnnotatedMember, if that could be avoided. I'll have to think about this when I have time.
But I think we can work with this, thank you @giulong !

@cowtowncoder cowtowncoder added the 2.20 Issues planned at 2.20 or later label Aug 22, 2025
@cowtowncoder cowtowncoder added this to the 2.20.0 milestone Aug 22, 2025
@cowtowncoder
Copy link
Member

@giulong I change handling slightly to enclose it all in POJOPropertiesCollector, using your basic idea. So now can merge it in 2.x for 2.20.0. Thank you again for contributing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.20 Issues planned at 2.20 or later

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants