AddDbContext<T>
AddDbContext<T> is an Entity Framework Core dependency-injection extension method that registers a DbContext type and configures its database options.
.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> →
Also covered in
Related concepts
- dependency injectionconfigures · Dependency injection is a software design technique in which a component receives its dependencies from outside rather than creating or locating them internally.
- Entity Framework Coreused by · Entity Framework Core is a cross-platform object-relational mapper for .NET that enables applications to query and persist data through .NET objects and APIs.
- dbcontextconfigures · DbContext is the Entity Framework Core class that coordinates database access, entity querying and change tracking, and persistence for an application’s data model.
- dependency injection containerconfigures · A dependency injection container is software that constructs or resolves objects and supplies their dependencies according to configured relationships.
Questions about AddDbContext<T>
What is AddDbContext<T>?
AddDbContext<T> is an Entity Framework Core dependency-injection extension method that registers a DbContext type and configures its database options.
Which Manning books explain AddDbContext<T>?
.NET in Action, Second Edition and ASP.NET Core in Action, 3e.
What is the difference between AddDbContext<T> and AddDbContextFactory extension method?
AddDbContext<T> is an Entity Framework Core dependency-injection extension method that registers a DbContext type and configures its database options. AddDbContextFactory is an Entity Framework Core service-registration method that registers a factory for creating DbContext instances.
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.

