Entity Framework Core Interview Question #6
What is DbContextOptions?
EF Core Fundamentals & DbContext Junior Beginner
Quick Interview Answer
DbContextOptions contains configuration used to construct a DbContext. It can describe the database provider, connection information, logging behavior, interceptors, query settings, and other EF Core options.
Detailed Explanation
DbContextOptions contains configuration used to construct a DbContext. It can describe the database provider, connection information, logging behavior, interceptors, query settings, and other EF Core options.
ASP.NET Core dependency injection normally builds DbContextOptions when AddDbContext is configured and injects it into the context constructor.
Keeping provider configuration outside the context class generally makes configuration easier to vary between development, testing, and production.
Code Example
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options)
{
}