Skip to content

Changed all field injection to constructor injection in NON-test classes#523

Open
JP-CC-Projects wants to merge 1 commit intodevfrom
issue522
Open

Changed all field injection to constructor injection in NON-test classes#523
JP-CC-Projects wants to merge 1 commit intodevfrom
issue522

Conversation

@JP-CC-Projects
Copy link
Copy Markdown
Contributor

@JP-CC-Projects JP-CC-Projects commented Mar 28, 2024

Why Constructor Injection?

One reason is that our unit tests may not work as expected.

As this helpful Baeldung article describes:

image

Other reasons:

  • Ease of Testing: Makes writing unit tests easier and clearer because dependencies can be passed directly to the constructor in test setups, eliminating the need for reflection or Spring-specific annotations.
  • No Spring Context Required: Allows for simpler unit tests that don't rely on Spring's context loading, leading to faster execution times.
  • Immutability and Safety: Encourages immutability and clear dependency declaration, improving the overall safety and maintainability of your application.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants