Here are the codes in .NET 6 in program.cs
builder.Services.AddDbContextPool<MyDbContext>(options =>
{
options.UseSqlServer(connstr);
});
builder.Services.AddDbContextFactory<MyDbContext>(options =>
{
options.UseSqlServer(connstr);
});
What is the difference between AddDbContextPool
and AddDbContextFactory
? What are the pro and cons of it?