/// <summary>
        /// Uses WebSocketManager Middleware
        /// Maps url starting with "/ws" for the WebSocketManager middleware.
        /// </summary>
        /// <param name="app">The application.</param>
        /// <param name="path"> Path of the websocket endpoint default is "/ws"</param>
        /// <param name="service"> Service that should be injected into WebSocketMiddleware on request</param>
        /// <returns></returns>
        public static IApplicationBuilder MapWebSocketService(this IApplicationBuilder app, string path = "/ws", WebSocketService service = null)
        {
            var mgr = app.ApplicationServices.GetService <WebSocketManager>();

            if (service == null)
            {
                mgr.WebSocketPaths.TryAdd(typeof(WebSocketService), path);
                return(app.Map(path, a => a.UseMiddleware <WebSocketMiddleware>()));
            }
            mgr.WebSocketPaths.TryAdd(service.GetType(), path);
            return(app.Map(path, a => a.UseMiddleware <WebSocketMiddleware>(service)));
        }
 public WebSocketMiddleware(RequestDelegate next, WebSocketService service)
 {
     _next   = next;
     Service = service;
 }