What is Dependency Injection
- Produce a loosely coupled code
- Any change in the class without affecting other object.
- Type of DI
- Constructor Injection
- parameter to inject dependencies in a class
- One parameterized constructor but no default constructor and you need to pass specified values to the constructor
- Setter Injection
- through properties of a class
- Interface-based injection
- through method
- Advantage
- Maintainability
- maintain code structure, single principle
- Flexibility
- loosely coupled code, flexible to use different ways.
- Testability
- easy to do unit testing
- Readability
- Logic in constructor.
No comments:
Post a Comment