Beispiel #1
0
        public static IConnectionBuilder UseEndPoint <TEndPoint>(this IConnectionBuilder connectionBuilder) where TEndPoint : EndPoint
        {
            var endpoint = connectionBuilder.ApplicationServices.GetRequiredService <TEndPoint>();

            // This is a terminal middleware, so there's no need to use the 'next' parameter
            return(connectionBuilder.Run(connection => endpoint.OnConnectedAsync(connection)));
        }
Beispiel #2
0
        /// <summary>
        /// Use the given <typeparamref name="TConnectionHandler"/> <see cref="ConnectionHandler"/>.
        /// </summary>
        /// <typeparam name="TConnectionHandler">The <see cref="Type"/> of the <see cref="ConnectionHandler"/>.</typeparam>
        /// <param name="connectionBuilder">The <see cref="IConnectionBuilder"/>.</param>
        /// <returns>The <see cref="IConnectionBuilder"/>.</returns>
        public static IConnectionBuilder UseConnectionHandler <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConnectionHandler>(this IConnectionBuilder connectionBuilder) where TConnectionHandler : ConnectionHandler
        {
            var handler = ActivatorUtilities.GetServiceOrCreateInstance <TConnectionHandler>(connectionBuilder.ApplicationServices);

            // This is a terminal middleware, so there's no need to use the 'next' parameter
            return(connectionBuilder.Run(connection => handler.OnConnectedAsync(connection)));
        }
 public static IConnectionBuilder UseHttpServer(this IConnectionBuilder builder, IHttpApplication application)
 {
     return(builder.Run(connection =>
     {
         var httpConnection = HttpServerProtocol.CreateFromConnection(connection);
         return application.ProcessRequests(httpConnection.ReadAllRequestsAsync());
     }));
 }
        public static IConnectionBuilder UseEndPoint <TEndPoint>(this IConnectionBuilder connectionBuilder) where TEndPoint : EndPoint
        {
            var endpoint = (TEndPoint)connectionBuilder.ApplicationServices.GetService(typeof(TEndPoint));

            if (endpoint == null)
            {
                throw new InvalidOperationException($"{nameof(EndPoint)} type {typeof(TEndPoint)} is not registered.");
            }
            // This is a terminal middleware, so there's no need to use the 'next' parameter
            return(connectionBuilder.Run(connection => endpoint.OnConnectedAsync(connection)));
        }
        public static IConnectionBuilder UseHub <THub>(this IConnectionBuilder socketBuilder) where THub : Hub
        {
            var endpoint = socketBuilder.ApplicationServices.GetRequiredService <HubEndPoint <THub> >();

            return(socketBuilder.Run(connection => endpoint.OnConnectedAsync(connection)));
        }