liveBook · Manning

Chapter 8: An introduction to dependency injection

What you will learn in chapter 8 of ASP.NET Core in Action, 3e

This introduction positions dependency injection as an essential ASP.NET Core pattern for loosely coupled applications and previews how the chapter will introduce and use it.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction positions dependency injection as an essential ASP.NET Core pattern for loosely coupled applications and previews how the chapter will introduce and use it.

Key terms: dependency injection, DI, loosely coupled code, ASP.NET Core, DI container, services, object lifetimes, third-party DI container

8.1 Understanding the benefits of dependency injection

This section introduces dependency injection as a way for ASP.NET Core to construct object dependency graphs so application code can focus on using services instead of creating them.

Key terms: dependency graph, single-responsibility principle, SRP, ceremony, implicit dependency, explicit dependency, dependency injection, DI container, IoC container, service

8.2 Creating loosely coupled code

This section shows how dependency injection promotes loosely coupled, testable code by passing dependencies as interfaces and registering their implementations in a DI container.

Key terms: coupling, tight coupling, loosely coupled code, RegisterUser, EmailSender, dependency, abstraction, interface, IEmailSender, SendEmail

8.3 Using dependency injection in ASP.NET Core

This section explains how ASP.NET Core’s built-in DI container supplies registered dependencies to minimal APIs and other framework components.

Key terms: DI container, built-in container, services, modular, composable, hosting model, RequestDelegateFactory, RegisterHandler, IEmailSender, EmailSender

8.4 Adding ASP.NET Core framework services to the container

This section explains how ASP.NET Core features and libraries register their required framework services with the built-in DI container.

Key terms: DI container, framework services, core services, Razor Pages, authentication, WebApplicationBuilder, Services, IServiceCollection, Program.cs, Add*() extension method

8.5 Using services from the DI container

This section explains how minimal API applications obtain registered services through endpoint-handler injection or, when startup code needs them, directly from WebApplication.Services.

Key terms: endpoint handler, LinkGenerator, DI container, minimal API infrastructure, dependency graph, constructor, dependencies, lifetime, Program.cs, WebApplication.Services

8.6 Summary

This summary recaps how ASP.NET Core’s dependency-injection container registers, creates, and supplies services, and why explicit dependencies are preferred.

Where this is used later

Concepts explained in this chapter

← Chapter 7: Model binding and validation in minimal APIs Chapter 9: Registering services with dependency injection →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.