-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Summary
Add a separate StormSocket.Hosting NuGet package that integrates StormSocket with ASP.NET Core's dependency injection and hosted service infrastructure. The main StormSocket package stays dependency-free.
Motivation
- ASP.NET Core developers expect
builder.Services.AddX()pattern - Manual
StartAsync()/StopAsync()lifecycle management is error-prone - No graceful shutdown, health checks, or
appsettings.jsonconfig binding currently
Proposed API
Registration
// WebSocket server
builder.Services.AddStormWebSocket(options =>
{
options.EndPoint = new IPEndPoint(IPAddress.Any, 8080);
options.WebSocket = new WebSocketOptions
{
Heartbeat = new() { PingInterval = TimeSpan.FromSeconds(15) },
};
});
// TCP server
builder.Services.AddStormTcp(options =>
{
options.EndPoint = new IPEndPoint(IPAddress.Any, 5000);
});Event handlers via DI
builder.Services.AddStormWebSocket(options => { ... })
.OnConnected(async (session, sp) =>
{
var db = sp.GetRequiredService<IDbContext>();
// ...
})
.OnMessageReceived(async (session, msg, sp) =>
{
var handler = sp.GetRequiredService<IChatHandler>();
await handler.Handle(session, msg);
});Configuration from appsettings.json
{
"StormSocket": {
"EndPoint": "0.0.0.0:8080",
"MaxConnections": 10000,
"WebSocket": {
"Heartbeat": {
"PingInterval": "00:00:15",
"MaxMissedPongs": 3
}
}
}
}builder.Services.AddStormWebSocket(builder.Configuration.GetSection("StormSocket"));Project structure
src/
├── StormSocket/ # existing — zero dependencies
└── StormSocket.Hosting/ # new package
├── StormSocket.Hosting.csproj # depends on: StormSocket + Microsoft.Extensions.Hosting
├── StormSocketHostedService.cs # IHostedService wrapper
└── ServiceCollectionExtensions.cs # AddStormTcp(), AddStormWebSocket()
Design notes
- Separate NuGet package —
dotnet add package StormSocket.Hosting - Same repo — mono-repo, both projects in
src/ - Main
StormSocketpackage stays dependency-free (console, worker, Unity, etc.) StormSocket.Hostingadds only the DI/hosting glue — no logic duplication- Graceful shutdown via
IHostApplicationLifetime(Ctrl+C, SIGTERM) - Server instances registered as singleton, resolved via
IServiceProvider
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request