Skip to content

Commit

Permalink
SONARJAVA-4649 Improve rule description: let it apply more genericall…
Browse files Browse the repository at this point in the history
…y to dependency injection frameworks (#4492)
  • Loading branch information
johann-beleites-sonarsource authored Oct 18, 2023
1 parent a02adef commit f684fc7
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h2>Why is this an issue?</h2>
<p>Spring supports dependency injection by using annotations such as <code>@Autowired</code>. This annotation can be used to inject beans via
constructor, setter, and field injection.</p>
<p>Dependency injection frameworks such as Spring support dependency injection by using annotations such as <code>@Inject</code> and
<code>@Autowired</code>. These annotation can be used to inject beans via constructor, setter, and field injection.</p>
<p>Generally speaking, field injection is discouraged. It allows the creation of objects in an invalid state and makes testing more difficult. The
dependencies are not explicit when instantiating a class that uses field injection.</p>
<p>Apart from that, field injection is not compatible with final fields. Keeping dependencies immutable where possible makes the code easier to
Expand Down

0 comments on commit f684fc7

Please sign in to comment.