public static IServiceProvider UseProxyWebSocket(this IServiceProvider serviceProvider, CancellationToken cancellationToken = default(CancellationToken)) { IList <IWebSocketConnector> connectors = InvocatorFactory.GetConnectors(serviceProvider); foreach (var connector in connectors) { Task.Run(async() => await connector.ConnectAsync(cancellationToken)); } return(serviceProvider); }
public static IApplicationBuilder UseProxyWebSockets(this IApplicationBuilder app, CancellationTokenSource cancellationTokenSource = null) { ThrowIfServiceNotRegistered(app.ApplicationServices); var appLifeTime = app.ApplicationServices.GetService <IApplicationLifetime>(); IList <IWebSocketConnector> connectors = InvocatorFactory.GetConnectors(app.ApplicationServices); foreach (var connector in connectors) { appLifeTime.ApplicationStopping.Register(OnShutdown, connector); Task.Run(async() => await connector.ConnectAsync(cancellationTokenSource)); } return(app); }
public static IApplicationBuilder UseProxyWebSockets(this IApplicationBuilder app, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfServiceNotRegistered(app.ApplicationServices); var appLifeTime = app.ApplicationServices.GetService <IApplicationLifetime>(); IList <IWebSocketConnector> connectors = InvocatorFactory.GetConnectors(app.ApplicationServices); foreach (var connector in connectors) { InvocatorsHelper.EnsureHostPair(connector.InvocatorContext); appLifeTime.ApplicationStopping.Register(OnShutdown, connector); Task.Factory.StartNew(async() => await connector.ConnectAsync(cancellationToken), TaskCreationOptions.LongRunning); } return(app); }
public static ProxyWebSocketsBuilder AddProxyWebSockets(this IServiceCollection services) { services.AddSingleton <IWebSocketConnector>(_ => InvocatorFactory.GetConnectors(_).First()); AddProxyWebSocketsInternal(services); return(new ProxyWebSocketsBuilder(services)); }