What is an Interface in the context of DI?

Updated Apr 28, 2026

Short answer

An interface defines a contract of methods and properties without implementing them, allowing DI to supply any concrete class that fulfills that contract.

Deep explanation

By depending on abstractions (interfaces) rather than concretions (classes), you achieve loose coupling. The consuming class doesn't know how the work is done, only what work can be done. This is the core of the Dependency Inversion Principle.

Real-world example

A payment processor depending on IPaymentGateway instead of StripeGateway, allowing easy switching to PayPalGateway later.

Common mistakes

  • Creating an interface for every single class automatically, even if the class is a basic data transfer object (DTO) or has no multiple implementations.

Follow-up questions

  • What is the Dependency Inversion Principle?

More Dependency Injection interview questions

View all →