Dependency Injection design pattern fulfills the dependency inversion principle of the SOLID design principles. There are three main forms of dependency injection:
- Constructor injection: An example of this is shown in the DIP section
- Setter injection: Let's look at an example code for setter injection:
public class OrderProcessorWithSetter : IOrderProcessor { private IOrderRepository _orderRepository; private IOrderNotifier _orderNotifier; public IOrderRepository Repository { get { return _orderRepository; } set { _orderRepository = value; } } public IOrderNotifier Notifier { get { return _orderNotifier; } set { _orderNotifier = value; } } public void Process(IOrder order) { //Perform validations.. ...