Best practices for configuring the DI pattern
The following are the best practices for configuring the DI pattern:
- Configuration files should be separated categorically. Application beans should be separate from infrastructure beans. Currently, it's a bit difficult to follow.
- Always specify the component name; never rely on generated names by the container.
- It is a best practice to give a name along with a description of what the pattern does, where to apply it, and the problems it addresses.
- The best practices for component scanning are as follows:
- The components are scanned at startup, and it scans the JAR dependencies as well.
- Bad practice: It scans all the packages of
com
andorg
. It increases the startup time of the application. Avoid such type of component scanning:
@ComponenttScan (( {{ "org", "com" }} ))
- Optimized: It scans only the specific packages as defined by us.
@ComponentScan ( { "com.packt.patterninspring.chapter4. ...