Mid OOP

How are interfaces used in dependency injection?

  • Interfaces allow DI frameworks to inject concrete implementations at runtime.
  • Promotes flexibility and testability.

public class CarService

private readonly IDriveable _vehicle;

public CarService(IDriveable vehicle) { _vehicle = vehicle; }

More from C# Programming Tutorial

All questions for this course