// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNetCore.Http.Connections; using Microsoft.AspNetCore.Http.Connections.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Builder { /// /// Extension methods for . /// public static class ConnectionsAppBuilderExtensions { /// /// Adds support for ASP.NET Core Connection Handlers to the request execution pipeline. /// /// The . /// A callback to configure connection routes. /// The same instance of the for chaining. public static IApplicationBuilder UseConnections(this IApplicationBuilder app, Action configure) { if (configure == null) { throw new ArgumentNullException(nameof(configure)); } var dispatcher = app.ApplicationServices.GetRequiredService(); var routes = new RouteBuilder(app); configure(new ConnectionsRouteBuilder(routes, dispatcher)); app.UseWebSockets(); app.UseRouter(routes.Build()); return app; } } }