public static void AddCustomDbContext(this IServiceCollection services, IConfiguration configuration, Assembly startupAssembly) { string projectDir = ServerPath.GetProjectPath(startupAssembly); var connectionString = configuration.GetConnectionString("DefaultConnection") .Replace("|DataDirectory|", Path.Combine(projectDir, "wwwroot", "app_data")); services.AddDbContext <ApplicationDbContext>(options => { options.UseSqlServer(connectionString, serverDbContextOptionsBuilder => { var minutes = (int)TimeSpan.FromMinutes(3).TotalSeconds; serverDbContextOptionsBuilder.CommandTimeout(minutes); serverDbContextOptionsBuilder.EnableRetryOnFailure(); }); }); }