Pro EP 63 : Dependency Inversion Principle of SOLID

Muhammad Waseem
Become .NET Pro !
1 min readAug 21, 2023

What is dependency inversion principle in SOLID , explained in C# ?

Dependency Inversion Principles is last one in SOLID principles and most important one it says, “High level module should not depend on low level module , instead both should depend on abstractions”

Benefits
- Decoupling
- Testability
- Reusability

Multiple ways to implement DIP
- Constructor injection
- Property injection
- Method injection

Example
Bad : Instead of using abstraction one using direct instantiation using new keyword everywhere.

Good : Relying on abstraction , registering dependency and using it via constructor injection (Method and Property injection as well)

We can achieve dependency injection using default DI container of .NET but we have some third party DI Container as well
- Autofac
- Ninject
- Castle Windsor

Whenever you’re ready, there are 4 ways I can help you

  1. Subscribe to my Weekly .NET Newsletter of C#/.NET with 7000+ Software Engineers.
  2. Promote yourself to 7000+ subscribers by Sponsoring my Newsletter
  3. Download my eBook at Gum Road which contains 30+ .NET Tips (With 2800+ Downloads)
  4. TTo get 100+ free and paid resources for learning C# and .NET visit this GitHub Repository

--

--