using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
namespace Esiur.AspNetCore;
/// Maps Esiur WebSocket endpoints into ASP.NET Core endpoint routing.
public static class EsiurEndpointRouteBuilderExtensions
{
///
/// Maps an EP WebSocket endpoint. The returned builder supports ASP.NET Core endpoint
/// conventions such as authorization and rate limiting.
///
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()
.HandleAsync(context))
.WithDisplayName("Esiur EP WebSocket");
}
}