[e6a6d9a] | 1 | using FinkiChattery.Api.Middleware;
|
---|
| 2 | using FinkiChattery.Api.Server;
|
---|
| 3 | using FinkiChattery.Api.Services;
|
---|
[7146ebb] | 4 | using FinkiChattery.Commands.Questioning;
|
---|
[e6a6d9a] | 5 | using FinkiChattery.Persistence.Context;
|
---|
[7146ebb] | 6 | using FluentValidation.AspNetCore;
|
---|
[ad058b3] | 7 | using Hangfire;
|
---|
[e6a6d9a] | 8 | using Microsoft.AspNetCore.Builder;
|
---|
| 9 | using Microsoft.AspNetCore.Hosting;
|
---|
| 10 | using Microsoft.AspNetCore.Mvc;
|
---|
| 11 | using Microsoft.EntityFrameworkCore;
|
---|
| 12 | using Microsoft.Extensions.Configuration;
|
---|
| 13 | using Microsoft.Extensions.DependencyInjection;
|
---|
| 14 | using Microsoft.Extensions.Hosting;
|
---|
| 15 |
|
---|
| 16 | namespace FinkiChattery.Api
|
---|
| 17 | {
|
---|
| 18 | public class Startup
|
---|
| 19 | {
|
---|
| 20 | public Startup(IConfiguration configuration)
|
---|
| 21 | {
|
---|
| 22 | Configuration = configuration;
|
---|
| 23 | AppSettings = new AppSettings(configuration);
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | public IConfiguration Configuration { get; }
|
---|
| 27 | public AppSettings AppSettings { get; }
|
---|
| 28 |
|
---|
| 29 | public void ConfigureServices(IServiceCollection services)
|
---|
| 30 | {
|
---|
| 31 | services.AddSingletonServices();
|
---|
| 32 | services.AddIdentityService(Configuration);
|
---|
| 33 | services.AddMediator();
|
---|
| 34 | services.AddEmailService();
|
---|
| 35 | services.AddOriginUrlSettings();
|
---|
| 36 | services.AddCurrentUser();
|
---|
[95d80e4] | 37 | services.AddUnitOfWork();
|
---|
[e6a6d9a] | 38 | services.AddAwsClient(Configuration);
|
---|
[ad058b3] | 39 | services.AddHangfireService(Configuration);
|
---|
[e6a6d9a] | 40 |
|
---|
[eb21f00] | 41 | string connectionString = "DefaultConnection";
|
---|
| 42 |
|
---|
| 43 | #if DEBUG_DOCKER
|
---|
| 44 | connectionString = "DefaultConnectionDocker";
|
---|
| 45 | #endif
|
---|
| 46 |
|
---|
[e6a6d9a] | 47 | services.AddDbContext<ApplicationDbContext>(options =>
|
---|
[eb21f00] | 48 | options.UseSqlServer(Configuration.GetConnectionString(connectionString)));
|
---|
[e6a6d9a] | 49 |
|
---|
| 50 | services.AddControllers()
|
---|
[7146ebb] | 51 | .ConfigureApiBehaviorOptions(options => options.InvalidModelStateResponseFactory = context => new BadRequestObjectResult(context.ModelState))
|
---|
| 52 | .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<AskQuestionValidator>());
|
---|
| 53 | services.AddApiVersioning();
|
---|
[e6a6d9a] | 54 |
|
---|
| 55 | services.AddCors(options =>
|
---|
| 56 | {
|
---|
| 57 | options.AddPolicy(
|
---|
| 58 | name: AppSettings.CorsSettings.CorsPolicyName,
|
---|
| 59 | builder => builder.WithOrigins(AppSettings.CorsSettings.AllowedCorsOrigins).AllowAnyHeader().AllowAnyMethod());
|
---|
| 60 | });
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
---|
| 64 | {
|
---|
| 65 | if (env.IsDevelopment())
|
---|
| 66 | {
|
---|
| 67 | app.UseDeveloperExceptionPage();
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | app.UseHttpsRedirection();
|
---|
| 71 |
|
---|
| 72 | app.UseMiddleware<ExceptionHandler>();
|
---|
| 73 |
|
---|
| 74 | app.UseRouting();
|
---|
| 75 | app.UseCors(AppSettings.CorsSettings.CorsPolicyName);
|
---|
| 76 |
|
---|
| 77 | app.UseAuthentication();
|
---|
| 78 |
|
---|
| 79 | app.UseAuthorization();
|
---|
| 80 |
|
---|
| 81 | app.UseEndpoints(endpoints =>
|
---|
| 82 | {
|
---|
| 83 | endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
|
---|
[ad058b3] | 84 | endpoints.MapHangfireDashboard();
|
---|
[e6a6d9a] | 85 | });
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|