public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContextPool<MyDbContext>(option => { option.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")); }, poolSize: 200);
var serviceProvider = builder.Services.BuildServiceProvider();
var dbContext = serviceProvider.GetService<MyDbContext>()
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
上面的代码,在vs2022 net7 asp.net core的progra.cs main方法中
builder.Services.BuildServiceProvider();这个地方提示警告
ASP0000 Calling 'BuildServiceProvider' from application code results in an additional copy of singleton services being created. Consider alternatives such as dependency injecting services as parameters to 'Configure'.
问题:
1、在这里获取dbcontext实例是不是这样获取,
2、该警告提示是否会影响程序,
3、在拿到dbcontex实例的情况下怎么消除该警告.