2
당신은 Startup.cs 파일에 다음 코드가 포함되어 ASP.NET 코어 RC2를 사용하여 새 웹 응용 프로그램 만들 때 -AddDbContext() 서비스 유형 활성화 모드
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
내 질문은 - 활성화 모드가 무엇인지를 이 DbContext 객체가 주입되는 이유는 무엇입니까? 일시적이거나 범위가 지정 되었습니까?
감사합니다. contextLifetime는 기본적으로 ServiceLifetime.Scoped
이지만, 변경 될 수 있습니다
serviceCollection.TryAddSingleton(p => DbContextOptionsFactory<TContext>(p, optionsAction));
serviceCollection.AddSingleton<DbContextOptions>(p => p.GetRequiredService<DbContextOptions<TContext>>());
serviceCollection.TryAdd(new ServiceDescriptor(typeof(TContext), typeof(TContext), contextLifetime));
: