-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
74 lines (62 loc) · 2.21 KB
/
Program.cs
File metadata and controls
74 lines (62 loc) · 2.21 KB
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
using Connectify.Db;
using Connectify.Db.Model;
using FluentValidation;
using GachiHubBackend.Extensions;
using GachiHubBackend.Hubs;
using GachiHubBackend.Hubs.Handlers;
using GachiHubBackend.Hubs.Interfaces;
using GachiHubBackend.Repositories;
using GachiHubBackend.Services;
using GachiHubBackend.Services.Interfaces;
using GachiHubBackend.Validation;
using Microsoft.AspNetCore.Authentication.JwtBearer;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthorization();
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.RegisterAuthentication(builder.GetJwtConfiguration());
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(opts =>
{
opts.SwaggerDoc("v1", new() { Title = "Connectify API", Version = "v1" });
opts.AddSignalRSwaggerGen();
});
builder.Services.AddSignalR();
builder.Services.AddCors(opts =>
{
opts.AddDefaultPolicy(policy =>
{
policy.AllowAnyHeader();
policy.AllowAnyMethod();
policy.AllowCredentials();
policy.SetIsOriginAllowed(_ => true);
});
});
builder.Services.AddHttpClient<IJanusService, JanusService>();
builder.Services.AddScoped<IValidator<User>, UserValidation>();
builder.Services.AddScoped<IValidator<Room>, RoomValidation>();
builder.Services.AddSingleton<AvatarService>();
builder.Services.AddDbContext<DbConnectifyContext>();
builder.Services.AddRepositories();
builder.Services.AddScoped<UserRepository>();
builder.Services.AddScoped<RoomRepository>();
builder.Services.AddScoped<MessagesRepository>();
builder.Services.AddScoped<IRoomHubContextService, RoomHubContextService>();
builder.Services.AddScoped<IRoomHubConnectedHandler, UserConnectedHandler>();
builder.Services.AddScoped<IRoomHubDisconnectedHandler, UserDisconnectedHandler>();
builder.Services.AddRoomHubHandlers();
builder.Services.AddScoped<IRoomHubHandlerService, RoomHubHandlerService>();
var app = builder.Build();
app.UseCors();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.MapHub<RoomHub>("/connectify");
app.Run();