示例#1
0
        public override async Task OnDisconnectedAsync(HubConnectionContext connection, Exception exception)
        {
            IServiceScope scope = null;

            try
            {
                scope = _serviceScopeFactory.CreateScope();

                var hubActivator = scope.ServiceProvider.GetRequiredService <IHubActivator <THub> >();
                var hub          = hubActivator.Create();
                try
                {
                    InitializeHub(hub, connection);
                    await hub.OnDisconnectedAsync(exception);
                }
                finally
                {
                    hubActivator.Release(hub);
                }
            }
            finally
            {
                await scope.DisposeAsync();
            }
        }
        public override async Task OnConnectedAsync(HubConnectionContext connection)
        {
            IServiceScope scope = null;

            try
            {
                scope = _serviceScopeFactory.CreateScope();

                var hubActivator = scope.ServiceProvider.GetRequiredService <IHubActivator <THub> >();
                var hub          = hubActivator.Create();
                try
                {
                    InitializeHub(hub, connection);

                    if (_onConnectedMiddleware != null)
                    {
                        var context = new HubLifetimeContext(connection.HubCallerContext, scope.ServiceProvider, hub);
                        await _onConnectedMiddleware(context);
                    }
                    else
                    {
                        await hub.OnConnectedAsync();
                    }
                }
                finally
                {
                    hubActivator.Release(hub);
                }
            }
            finally
            {
                await scope.DisposeAsync();
            }
        }
示例#3
0
        private ValueTask CleanupInvocation(HubConnectionContext connection, HubMethodInvocationMessage hubMessage, IHubActivator <THub> hubActivator,
                                            THub hub, IServiceScope scope)
        {
            if (hubMessage.StreamIds != null)
            {
                foreach (var stream in hubMessage.StreamIds)
                {
                    connection.StreamTracker.TryComplete(CompletionMessage.Empty(stream));
                }
            }

            hubActivator?.Release(hub);

            return(scope.DisposeAsync());
        }
示例#4
0
        private ValueTask CleanupInvocation(HubConnectionContext connection, HubMethodInvocationMessage hubMessage, IHubActivator <THub> hubActivator,
                                            THub hub, IServiceScope scope)
        {
            if (hubMessage.StreamIds != null)
            {
                foreach (var stream in hubMessage.StreamIds)
                {
                    try
                    {
                        connection.StreamTracker.Complete(CompletionMessage.Empty(stream));
                    }
                    // ignore failures, it means the client already completed the streams
                    catch (KeyNotFoundException) { }
                }
            }

            hubActivator?.Release(hub);

            return(scope.DisposeAsync());
        }
        public ValueTask DisposeAsync()
        {
            Services = null;

            return(_scope.DisposeAsync());
        }