dotnet / dotnet/EntityFramework.Docs

How is DbContext resolved at design-time in new ASP.NET Core projects?

Open
#4,478 2 comments 0 reactions 0 assignees View on GitHub
area-tools
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

The [Design-time DbContext Creation](https://learn.microsoft.com/en-us/ef/core/cli/dbcontext-creation) article in the docs explains how some EF Core Tools commands need to instantiate the application's `DbContext` in order to gather certain information, and that in ASP.NET Core projects, this is done by calling `Program.CreateHostBuilder()` to build the DI container, and then requesting the `DbContext` from the container.

This makes sense, except that it's been quite a while since ASP.NET Core projects no longer have a `Program.CreateHostBuilder()`, `Startup.cs`, etc. and all that code is now "flattened", if you will, inside `Program.cs`.

So, I was wondering how EF accomplishes the same thing now in this new structure? Does it, for example, execute everything in `Program.cs` up until `app.Build()`, or some sort of logic like that?

It would also be nice if the documentation I linked to could be updated to reflect this change in ASP.NET Core.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.