-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
executable file
·60 lines (50 loc) · 1.92 KB
/
Program.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
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using Scandium.Data;
using FastEndpoints.Swagger;
using Scandium.Services.Abstract;
using Scandium.Services;
using Scandium.Extensions.ServiceExtensions;
using Scandium.Middlewares;
using Scandium.Actions;
using Scandium.Services.Concreate;
using Scandium.Data.Abstract;
using Scandium.Data.Concreate;
using Scandium.Hubs;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors();
builder.Services.AddFastEndpoints();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddHttpContextAccessor();
builder.Services.AddSwaggerDoc();
builder.Services.AddSignalR();
builder.Services.AddTransient<ExceptionHandlingMiddleware>();
builder.Services.AddSettings(builder.Configuration);
builder.Services.AddEntityFrameworkNpgsql()
.AddDbContext<AppDbContext>(opt => opt
.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnectionString")));
builder.Services.AddCustomJwtAuthentication(builder.Configuration);
builder.Services.AddScoped<IJwtService, JwtService>();
builder.Services.AddTransient<IHttpContextService, HttpContextService>();
builder.Services.AddScoped<IUserRepo, UserRepo>();
builder.Services.AddScoped<IMessageRepository, MessageRepository>();
builder.Services.AddScoped<IFriendshipRequestRepository, FriendshipRequestRepository>();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseOpenApi();
app.UseSwaggerUi3(c => c.ConfigureDefaults());
}
app.UseRouting();
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseMiddleware<ExceptionHandlingMiddleware>();
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
app.UseAuthentication();
app.UseAuthorization();
app.MapHub<MessageHub>("/hubs/messageHub");
app.MapHub<FriendshipRequestHub>("/hubs/friendshipRequestHub");
app.UseFastEndpoints(FastEndpointsAction.GetConfigActions);
app.Run();