@@ -53,11 +53,26 @@ public static IServiceProvider MigrateDatabase(this IServiceProvider serviceProv
5353 private static void AddDatabaseServices ( IServiceCollection services , IConfiguration configuration )
5454 {
5555 services . AddDbContext < ProjectVGDbContext > ( options =>
56- options . UseSqlServer ( configuration . GetConnectionString ( "DefaultConnection" ) ,
57- sqlOptions => sqlOptions . EnableRetryOnFailure (
58- maxRetryCount : 3 ,
59- maxRetryDelay : TimeSpan . FromSeconds ( 10 ) ,
60- errorNumbersToAdd : null ) ) ) ;
56+ options . UseSqlServer ( configuration . GetConnectionString ( "DefaultConnection" ) ,
57+ sqlOptions => {
58+ sqlOptions . EnableRetryOnFailure (
59+ maxRetryCount : 5 ,
60+ maxRetryDelay : TimeSpan . FromSeconds ( 30 ) ,
61+ errorNumbersToAdd : new int [ ] {
62+ 2 , // System.Data.SqlClient.SqlException: Connection timeout
63+ 20 , // The instance of SQL Server you attempted to connect to does not support encryption
64+ 64 , // A connection was successfully established with the server, but then an error occurred during the login process
65+ 233 , // The client was unable to establish a connection because of an error during connection initialization process before login
66+ 10053 , // A transport-level error has occurred when receiving results from the server
67+ 10054 , // The connection was forcibly closed by the remote host
68+ 10060 , // A network-related or instance-specific error occurred while establishing a connection to SQL Server
69+ 40197 , // The service has encountered an error processing your request. Please try again (Azure SQL)
70+ 40501 , // The service is currently busy. Retry the request after 10 seconds (Azure SQL)
71+ 40613 // Database is currently unavailable (Azure SQL)
72+ } ) ;
73+ sqlOptions . CommandTimeout ( 120 ) ;
74+ sqlOptions . MigrationsHistoryTable ( "__EFMigrationsHistory" , "dbo" ) ;
75+ } ) ) ;
6176 }
6277
6378 /// <summary>
@@ -138,8 +153,10 @@ private static void AddAuthServices(IServiceCollection services, IConfiguration
138153 } ;
139154
140155 services . AddSingleton ( jwtSettings ) ;
141- services . AddScoped < IJwtProvider , JwtProvider > ( sp =>
142- new JwtProvider ( jwtKey , jwtSettings . Issuer , jwtSettings . Audience , jwtSettings . AccessTokenExpirationMinutes , jwtSettings . RefreshTokenExpirationMinutes ) ) ;
156+ services . AddScoped < IJwtProvider , JwtProvider > ( sp => {
157+ var logger = sp . GetRequiredService < ILogger < JwtProvider > > ( ) ;
158+ return new JwtProvider ( jwtKey , jwtSettings . Issuer , jwtSettings . Audience , jwtSettings . AccessTokenExpirationMinutes , jwtSettings . RefreshTokenExpirationMinutes , logger ) ;
159+ } ) ;
143160
144161 services . AddScoped < ITokenService , TokenService > ( ) ;
145162
0 commit comments