liveBook · Manning

AddDbContext<T>

AddDbContext<T> is an Entity Framework Core dependency-injection extension method that registers a DbContext type and configures its database options.

How 2 Manning books explain it

.NET in Action, Second Edition

AddDbContext is an Entity Framework Core service-registration method that registers a DbContext type with a dependency injection container.

How it is used
Configures ASP.NET Core dependency injection so API controllers can receive a request-scoped Entity Framework Core context.
How deep it goes
Explains registration, request lifetime, disposal, and constructor injection, but stops short of internal dependency-injection mechanics.
Examples
Uses CatalogContext, CatalogController, SQLite startup configuration, database seeding, and injected query operations.
What you can do after
Operate/configure ASP.NET Core services with a registered DbContext that controllers can consume safely within requests.

Read how .NET in Action, Second Edition explains AddDbContext<T> →

ASP.NET Core in Action, 3e

AddDbContext<T> is an ASP.NET Core dependency-injection extension method that registers an Entity Framework Core database context type and configures its provider and options.

How it is used
Registers an EF Core DbContext in ASP.NET Core dependency injection while configuring its provider and connection string.
How deep it goes
Explains the options configuration function, provider selection, connection loading, and scoped lifetime without detailing provider internals.
Examples
Uses AppDbContext, DefaultConnection, Program.cs, UseSqlite, and the Microsoft.EntityFrameworkCore.SQLite package.
What you can do after
Operate/configure an ASP.NET Core application so injected DbContext instances can interact with EF Core and its database.

Read how ASP.NET Core in Action, 3e explains AddDbContext<T> →

Related concepts

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.