// 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.Connections; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.SignalR { /// /// Extension methods for . /// public static class SignalRConnectionBuilderExtensions { /// /// Configure the connection to host the specified type. /// /// The type to host on the connection. /// The connection to configure. /// The same instance of the for chaining. public static IConnectionBuilder UseHub(this IConnectionBuilder connectionBuilder) where THub : Hub { var marker = connectionBuilder.ApplicationServices.GetService(typeof(SignalRCoreMarkerService)); if (marker == null) { throw new InvalidOperationException("Unable to find the required services. Please add all the required services by calling " + "'IServiceCollection.AddSignalR' inside the call to 'ConfigureServices(...)' in the application startup code."); } return connectionBuilder.UseConnectionHandler>(); } } }