Skip to content

Field injection in quarkus #38474

Answered by Ladicek
BrianH85 asked this question in Q&A
Jan 30, 2024 · 4 comments · 21 replies
Discussion options

You must be logged in to vote

The concerns in the linked article generally apply to all full-featured dependency injection containers, including CDI. From a purist perspective, constructor injection should obviously be preferred to field injection. On the other hand, field injection is immensely pragmatic (what's the point of writing a constructor that just assigns its parameters to fields?). Specifically when it comes to testing and mocking, Quarkus has multiple tools that make testing a breeze even in presence of field injection (see https://quarkus.io/guides/getting-started-testing).

Replies: 4 comments 21 replies

Comment options

You must be logged in to vote
13 replies
@Pankraz76
Comment options

@Pankraz76
Comment options

@Pankraz76
Comment options

@Pankraz76
Comment options

@Ladicek
Comment options

Ladicek Jun 23, 2025
Collaborator

Comment options

You must be logged in to vote
4 replies
@manovotn
Comment options

@Ladicek
Comment options

Ladicek Jan 30, 2024
Collaborator

@mkouba
Comment options

mkouba Jan 30, 2024
Collaborator

@edeandrea
Comment options

Answer selected by cescoffier
Comment options

You must be logged in to vote
3 replies
@edeandrea
Comment options

@Chealer
Comment options

@mkouba
Comment options

mkouba Oct 3, 2024
Collaborator

Comment options

You must be logged in to vote
1 reply
@omasseau
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area/arc Issue related to ARC (dependency injection)
9 participants