-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
enhancement: use constructor injection instead of field injection #1839
enhancement: use constructor injection instead of field injection #1839
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1839 +/- ##
============================================
+ Coverage 48.31% 49.87% +1.55%
- Complexity 1913 1914 +1
============================================
Files 394 394
Lines 11680 12075 +395
Branches 1225 1225
============================================
+ Hits 5643 6022 +379
- Misses 5590 5606 +16
Partials 447 447
Continue to review full report at Codecov.
|
There are some Field Injections left and some workarounds such as |
@kezhenxu94 Thanks! I can see using constructor injection makes the program more robust and more friendly to tests. However, I'm curious about how did you manage to modify so many places, by hand or by some tool? I also notice there are some places marked with |
Modifying those places with modern IDE is a easy task, I'm using Intellij.
The rule is that when the dependencies form a circle, i.e. |
Thanks for the explanation. Regarding the cyclic reference, how did you identify such case, manually or by some tool? |
It's hard to identify that, though there are tools to detect that in this thread, I identified by running the test cases and Spring will print out the cyclic denpendencies graph. |
Thanks! Will take a detailed look soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…olloconfig#1839) * enhancement: use constructor injection instead of field injection * remove unused field
This patch uses Constructor Injection to avoid the drawbacks of Field Injection. What's more, Spring Documentation also recommends using Constructor Injection here
Here are some of the drawbacks of Field Injection listed in this article:
Disallows immutable field declaration
Eases single responsibility principle violation
Tightly coupled with dependency injection container
Hidden dependencies