| | 1 | | using Infrastructure.Context; |
| | 2 | | using Infrastructure.Repository; |
| | 3 | | using Microsoft.EntityFrameworkCore; |
| | 4 | | using Microsoft.EntityFrameworkCore.Diagnostics; |
| | 5 | | using Microsoft.Extensions.Configuration; |
| | 6 | | using Microsoft.Extensions.DependencyInjection; |
| | 7 | | using Microsoft.Extensions.Hosting; |
| | 8 | | using Microsoft.Extensions.Logging; |
| | 9 | |
|
| | 10 | | namespace Infrastructure; |
| | 11 | | public static class DependencyInjectionContainer { |
| | 12 | | const int POOL_SIZE = 1024; |
| | 13 | |
|
| 1 | 14 | | public static IServiceCollection AddInfrastructure(this IServiceCollection services, IHostEnvironment environment, ICo |
| | 15 | |
|
| 1 | 16 | | services.AddScoped<NorthwindRepository>(); |
| | 17 | |
|
| 1 | 18 | | var connection = configuration.GetConnectionString("DefaultConnection"); |
| | 19 | |
|
| 1 | 20 | | services.AddPooledDbContextFactory<NorthwindContext>((sp, options) => { |
| 0 | 21 | | options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); |
| 1 | 22 | |
|
| 0 | 23 | | if (environment.IsDevelopment()) { |
| 0 | 24 | | options.EnableDetailedErrors(); |
| 0 | 25 | | options.EnableSensitiveDataLogging(); |
| 0 | 26 | | } |
| 0 | 27 | | var loggerFactory = sp.GetRequiredService<ILoggerFactory>(); |
| 0 | 28 | | options.UseLoggerFactory(loggerFactory); |
| 1 | 29 | |
|
| 0 | 30 | | options.LogTo( |
| 0 | 31 | | message => loggerFactory.CreateLogger("EFCore"), |
| 0 | 32 | | [DbLoggerCategory.Database.Command.Name], |
| 0 | 33 | | LogLevel.Information, |
| 0 | 34 | | DbContextLoggerOptions.SingleLine |
| 0 | 35 | | ); |
| 1 | 36 | |
|
| 0 | 37 | | options.UseNpgsql(connection, sqlOptions => { |
| 0 | 38 | | sqlOptions.EnableRetryOnFailure( |
| 0 | 39 | | maxRetryCount: 10, |
| 0 | 40 | | maxRetryDelay: TimeSpan.FromSeconds(10), |
| 0 | 41 | | errorCodesToAdd: [] |
| 0 | 42 | | ); |
| 0 | 43 | | }); |
| 1 | 44 | |
|
| 0 | 45 | | }, |
| 1 | 46 | | POOL_SIZE); |
| | 47 | |
|
| 1 | 48 | | return services; |
| 1 | 49 | | } |
| | 50 | | } |