Interviews2 answers
What is dependency injection in C#?
2 Answers
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
{
}
Rajendra TripathyPosted Jul 30, 2014, 2:16 AM EDT
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.
Akshay PatelPosted Aug 30, 2012, 12:43 AM EDT

