Dependency Injection (DI) is a design pattern that demonstrates how to create loosely coupled classes. Typically, if Class1 and Class2 were loosely coupled, Class1 would have a reference to an interface instead of a direct binary reference to Class2. For Ex.. public class Class1 {public IClass2 Class2 { get; set; } }public interface IClass2 { }public class Class2 : IClass2 { }
Dependency injection is a way of implementing inversion of control. There are four main method to implement DI. 1.Constructor methodology 2.Getter and Setter 3.Interface based DI 4.Service Locator.