1 | using FinkiChattery.Api.Middleware;
|
---|
2 | using FinkiChattery.Api.Server;
|
---|
3 | using FinkiChattery.Api.Services;
|
---|
4 | using FinkiChattery.Commands.Questioning;
|
---|
5 | using FinkiChattery.Persistence.Context;
|
---|
6 | using FluentValidation.AspNetCore;
|
---|
7 | using Hangfire;
|
---|
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();
|
---|
37 | services.AddUnitOfWork();
|
---|
38 | services.AddAwsClient(Configuration);
|
---|
39 | services.AddHangfireService(Configuration);
|
---|
40 |
|
---|
41 | string connectionString = "DefaultConnection";
|
---|
42 |
|
---|
43 | #if DEBUG_DOCKER
|
---|
44 | connectionString = "DefaultConnectionDocker";
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | services.AddDbContext<ApplicationDbContext>(options =>
|
---|
48 | options.UseSqlServer(Configuration.GetConnectionString(connectionString)));
|
---|
49 |
|
---|
50 | services.AddControllers()
|
---|
51 | .ConfigureApiBehaviorOptions(options => options.InvalidModelStateResponseFactory = context => new BadRequestObjectResult(context.ModelState))
|
---|
52 | .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<AskQuestionValidator>());
|
---|
53 | services.AddApiVersioning();
|
---|
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?}");
|
---|
84 | endpoints.MapHangfireDashboard();
|
---|
85 | });
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|