Esempio n. 1
0
 public void ConfigureServices(IServiceCollection services)
 {
     services
     .AddScoped <DbSeeder>()
     .AddDbContext <ApplicationDbContext>((provider, builder) =>
                                          builder.UseNpgsql(EnvironmentExtensions.GetValueOrThrow <string>("CONNECTION_STRING"))
                                          .UseLoggerFactory(LoggerFactory.Create(loggingBuilder =>
     {
         if (provider.GetRequiredService <IWebHostEnvironment>().IsDevelopment())
         {
             loggingBuilder.AddConsole();
         }
     })))
     .AddScoped <IAuthService, AuthService>()
     .AddSingleton <IEmailService, EmailService>()
     .AddSingleton <IResetPasswordTokenProvider, ResetPasswordTokenProvider>()
     .AddJwtBearerAuth(_configuration)
     .AddIdentity()
     .Configure <EmailOptions>(_configuration.GetSection(nameof(EmailOptions)))
     .AddSwagger()
     .AddLocalization(options => options.ResourcesPath = "Resources")
     .AddControllers(options =>
     {
         options.Filters.Add <ErrorableResultFilterAttribute>();
         options.Filters.Add(new ProducesAttribute(MediaTypeNames.Application.Json));
     })
     .AddDataAnnotationsLocalization(options => options.DataAnnotationLocalizerProvider = (_, factory) => factory.Create(typeof(SharedResource)))
     .AddJsonOptions(options => options
                     .JsonSerializerOptions
                     .Converters
                     .Add(new JsonStringEnumConverter()));
 }