mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-07-30 17:30:40 +00:00
ASP.Net
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Esiur.AspNetCore;
|
||||
|
||||
/// <summary>Maps Esiur WebSocket endpoints into ASP.NET Core endpoint routing.</summary>
|
||||
public static class EsiurEndpointRouteBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps an EP WebSocket endpoint. The returned builder supports ASP.NET Core endpoint
|
||||
/// conventions such as authorization and rate limiting.
|
||||
/// </summary>
|
||||
public static IEndpointConventionBuilder MapEsiur(
|
||||
this IEndpointRouteBuilder endpoints,
|
||||
string pattern = "/esiur")
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(endpoints);
|
||||
if (string.IsNullOrWhiteSpace(pattern))
|
||||
throw new ArgumentException("An endpoint route pattern is required.", nameof(pattern));
|
||||
|
||||
return endpoints.Map(
|
||||
pattern,
|
||||
context => context.RequestServices
|
||||
.GetRequiredService<EsiurWebSocketEndpoint>()
|
||||
.HandleAsync(context))
|
||||
.WithDisplayName("Esiur EP WebSocket");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user