-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
44 lines (37 loc) · 1.28 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
using CallorieCounter;
using CallorieCounter.GraphQL;
using CallorieCounter.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddGrpc();
builder.Services.AddSingleton<WebSocketHandler>();
builder.Services.AddSingleton<RabbitMqService>();
builder.Services.AddSingleton<GrpcClientService>();
builder.Services.AddSingleton<IMealService, MealService>();
builder.Services.AddSingleton<IProductService, ProductService>();
builder.Services.AddSingleton<IUserService, UserService>();
builder.Services
.AddGraphQLServer()
.AddQueryType<Query>()
.AddMutationType<Mutation>();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseWebSockets();
app.UseHttpsRedirection();
app.UseAuthorization();
var webSocketHandler = app.Services.GetRequiredService<WebSocketHandler>();
app.MapControllers();
app.MapGraphQL();
app.MapGrpcService<CalorieCounterService>();
app.MapGet("/", () => "Сервис работает. Используйте gRPC-клиент для взаимодействия.");
app.Map("/ws", async context =>
{
await webSocketHandler.HandleWebSocketAsync(context);
});
app.Run();