7 Using dependency injection to manage services

This chapter covers

  • Understanding the role of dependency injection
  • Examining dependency injection in ASP.NET Core
  • Creating and using your own services
  • Managing service lifetime

Dependency injection (DI) is a software engineering technique included as a feature in many web frameworks these days. Its raison d’être is enabling loose coupling between software components, resulting in code that is less brittle, more adaptable to change, easier to maintain, and easier to test. If you have worked with dependency injection before, all of this will feel familiar to you. In case dependency injection is a new concept to you, this chapter will help by explaining what it is and why you should care.

DI is at ...

Get ASP.NET Core Razor Pages in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.