Mid SOLID

Can DI be used without a DI container? How?

Yes, DI can be implemented manually without using a DI container. You simply pass

dependencies through constructors or methods:

public class OrderService

private readonly IOrderRepository _repo;

public OrderService(IOrderRepository repo)

_repo = repo;

// Manual injection

var repo = new OrderRepository();

var service = new OrderService(repo);

This is suitable for small or simple applications, though not scalable for large apps.

More from Design Patterns in C#

All questions for this course