-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartup.cs
153 lines (118 loc) · 4.91 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using FluentValidation;
using FluentValidation.AspNetCore;
using Jantzch.Server2.Application.Abstractions.Configuration;
using Jantzch.Server2.Application.Abstractions.Excel;
using Jantzch.Server2.Application.Abstractions.Google;
using Jantzch.Server2.Application.Abstractions.Jwt;
using Jantzch.Server2.Application.Orders;
using Jantzch.Server2.Application.Services.DataShapingService;
using Jantzch.Server2.Application.Services.Pagination;
using Jantzch.Server2.Application.Services.PropertyChecker;
using Jantzch.Server2.Domain.Entities.Clients.Services;
using Jantzch.Server2.Infraestructure;
using Jantzch.Server2.Infraestructure.Errors;
using Jantzch.Server2.Infraestructure.Services.PropertyChecker;
using Jantzch.Server2.Infrastructure;
using Jantzch.Server2.Infrastructure.Configuration;
using Jantzch.Server2.Infrastructure.Excel;
using Jantzch.Server2.Infrastructure.Google;
using Jantzch.Server2.Infrastructure.Json;
using Jantzch.Server2.Infrastructure.Jwt;
using Jantzch.Server2.Infrastructure.MongoDb;
using Jantzch.Server2.Infrastructure.Repositories;
using Jantzch.Server2.Infrastructure.Security;
using Jantzch.Server2.Infrastructure.Services;
using MediatR;
using System.Reflection;
namespace Jantzch.Server2;
public class Startup
{
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.ConfigureMongoDB();
services.AddMediatR(
config => config.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())
);
services.AddScoped(
typeof(IPipelineBehavior<,>),
typeof(DBContextTransactionPipelineBehavior<,>)
);
services.AddJwtAuthentication();
services.AddFluentValidationAutoValidation();
services.AddFluentValidationClientsideAdapters();
services.AddValidatorsFromAssemblyContaining<Startup>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddLocalization(x => x.ResourcesPath = "Resources");
services.AddSignalR();
services.AddRepositories();
services.AddServices(configuration);
services.AddTransient<IClientService, ClientService>();
services.AddTransient<IPropertyCheckerService, PropertyCheckerService>();
services.AddTransient<IPaginationService, PaginationService>();
services.AddTransient<IDataShapingService, DataShapingService>();
services.AddTransient<IExcelService, ClosedXmlService>();
services.AddSingleton<IConfigurationService, ConfigurationService>();
services.AddScoped<IJwtService, JwtService>();
services.AddAutoMapper(Assembly.GetExecutingAssembly());
services
.AddMvc(opt =>
{
opt.Filters.Add(typeof(ValidatorActionFilter));
opt.EnableEndpointRouting = false;
opt.InputFormatters.Insert(0, JsonPatchFormatter.GetJsonPatchInputFormatter());
})
.AddCustomJsonOptions();
services.AddHttpClient<IGoogleMapsService, GoogleMapsService>((provider, httpClinet) =>
{
httpClinet.BaseAddress = new Uri("https://maps.googleapis.com/maps/api/");
});
services.AddSwaggerGen();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseCors(opt =>
{
opt
.WithOrigins("http://localhost:8080", "http://localhost:5016", "http://192.168.100.10:5016")
.SetIsOriginAllowedToAllowWildcardSubdomains()
.SetIsOriginAllowed(x => true)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
.WithExposedHeaders("X-Pagination");
});
}
else
{
app.UseCors(opt =>
{
opt
.WithOrigins(Environment.GetEnvironmentVariable("CLIENT_DOMAIN"), Environment.GetEnvironmentVariable("LOGIN_DOMAIN"))
.SetIsOriginAllowedToAllowWildcardSubdomains()
.SetIsOriginAllowed(x => true)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
.WithExposedHeaders("X-Pagination");
});
}
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseHsts();
app.UseMiddleware<ErrorHandlingMiddleware>();
app.UseMvc();
app.UseSwagger();
// Enable middleware to serve swagger-ui assets(HTML, JS, CSS etc.)
app.UseSwaggerUI();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<OrderHub>("/orderhub")
.RequireAuthorization();
// outras rotas...
});
app.ApplicationServices.GetRequiredService<ILoggerFactory>();
}
}