36 lines
1.5 KiB
C#
36 lines
1.5 KiB
C#
using AyCode.Services.SignalRs;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.AspNetCore.SignalR.Protocol;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace AyCode.Services.Server.SignalRs;
|
|
|
|
/// <summary>
|
|
/// Server-side registration extension for the <see cref="AyCodeBinaryHubProtocol"/> (<c>"acbinary"</c>).
|
|
/// Mirrors the ASP.NET Core idiomatic <c>AddJsonProtocol(...)</c> / <c>AddMessagePackProtocol(...)</c>.
|
|
/// <para>
|
|
/// Kept separate from the client-side extension (in <c>AyCode.Services</c>) so that pure client
|
|
/// projects (MAUI, WASM) do not pull in the server SignalR assembly
|
|
/// (<c>Microsoft.AspNetCore.SignalR.Core</c>) through a transitive reference.
|
|
/// </para>
|
|
/// </summary>
|
|
public static class AcSignalRServerProtocolExtensions
|
|
{
|
|
/// <summary>
|
|
/// Registers <see cref="AyCodeBinaryHubProtocol"/> (name: <c>"acbinary"</c>) as a SignalR hub
|
|
/// protocol on the server. Options can be configured via either:
|
|
/// <list type="bullet">
|
|
/// <item><c>services.Configure<AcBinaryHubProtocolOptions>(...)</c> — DI-level defaults</item>
|
|
/// <item>The optional <paramref name="configure"/> callback — overrides DI values inline</item>
|
|
/// </list>
|
|
/// </summary>
|
|
public static ISignalRServerBuilder AddAcBinaryProtocol(
|
|
this ISignalRServerBuilder builder,
|
|
Action<AcBinaryHubProtocolOptions>? configure = null)
|
|
{
|
|
builder.Services.AddSingleton<IHubProtocol>(sp =>
|
|
AcSignalRProtocolExtensions.BuildProtocol(sp, configure));
|
|
return builder;
|
|
}
|
|
}
|