public static IWebSocketHostBuilder ConfigureWebSocketMessageHandler(this IWebSocketHostBuilder builder, Func <WebSocketSession, WebSocketPackage, Task> handler) { return(builder.ConfigureServices((ctx, services) => { services.AddSingleton <Func <WebSocketSession, WebSocketPackage, Task> >(handler); }) as IWebSocketHostBuilder); }
public static IWebSocketHostBuilder UseCommand <TKey, TPackageInfo, TPackageMapper>(this IWebSocketHostBuilder builder) where TPackageInfo : class, IKeyedPackageInfo <TKey> where TPackageMapper : class, IPackageMapper <WebSocketPackage, TPackageInfo>, new() { return(builder.ConfigureServices((ctx, services) => { services.AddSingleton <IWebSocketCommandMiddleware, WebSocketCommandMiddleware <TKey, TPackageInfo, TPackageMapper> >(); }).ConfigureServices((ctx, services) => { services.Configure <CommandOptions>(ctx.Configuration?.GetSection("serverOptions")?.GetSection("commands")); }) as IWebSocketHostBuilder); }
public static IWebSocketHostBuilder UseCommand <TPackageInfo, TPackageMapper>(this IWebSocketHostBuilder builder) where TPackageInfo : class where TPackageMapper : class, IPackageMapper <WebSocketPackage, TPackageInfo>, new() { var keyType = CommandMiddlewareExtensions.GetKeyType <TPackageInfo>(); var commandMiddlewareType = typeof(WebSocketCommandMiddleware <, ,>).MakeGenericType(keyType, typeof(TPackageInfo), typeof(TPackageMapper)); return(builder.ConfigureServices((ctx, services) => { services.AddSingleton(typeof(IWebSocketCommandMiddleware), commandMiddlewareType); }).ConfigureServices((ctx, services) => { services.Configure <CommandOptions>(ctx.Configuration?.GetSection("serverOptions")?.GetSection("commands")); }) as IWebSocketHostBuilder); }