-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathProgram.cs
More file actions
27 lines (20 loc) · 751 Bytes
/
Copy pathProgram.cs
File metadata and controls
27 lines (20 loc) · 751 Bytes
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
using FreeRedis;
using WebsocketCluster.Handlers;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton(provider => {
var logger = provider.GetService<ILogger<WebSocketChannelHandler>>();
RedisClient cli = new RedisClient(builder.Configuration["Redis:ConnectionString"]);
cli.Notice += (s, e) => logger?.LogInformation(e.Log);
return cli;
});
builder.Services.AddSingleton<WebSocketHandler>().AddSingleton<WebSocketChannelHandler>();
builder.Services.AddControllers();
var app = builder.Build();
var webSocketOptions = new WebSocketOptions
{
KeepAliveInterval = TimeSpan.FromMinutes(2)
};
app.UseWebSockets(webSocketOptions);
app.MapGet("/", () => "Hello World!");
app.MapControllers();
app.Run();