ClassA class needs to use a ClassB component, then the best you can do is to make your ClassA aware of an IClassB interface rather than a ClassB. In this way, you can change the implementation of the ClassB at any time.
We can implement dependency injection following three ways:
- Constructor Injection
- Property injection
- Method injection
In Constructor dependency you need to pass specified values at the time of creation to initiate the object.
2-Property injection(Setter Injection)
Property injection is also called setter Injection. It does not require any modification in the constructor. We are passing an object instance of service class using SET operation.
In Method injection we pass the service class object instance in Method.