Esempio n. 1
0
        private Func <T, TResult> GetNext(IMiddleware <T, TResult> currentMiddleware, IList <IMiddleware <T, TResult> > mItems)
        {
            if (currentMiddleware == null)
            {
                return(null);
            }

            var currentMiddlewareIndex = mItems.IndexOf(currentMiddleware);
            var nextMiddleware         = mItems.ElementAtOrDefault(currentMiddlewareIndex + 1);

            if (nextMiddleware == null)
            {
                return(input => currentMiddleware.Next(null, input));
            }

            return(input => currentMiddleware.Next(nextMiddleware, input));
        }
Esempio n. 2
0
        private async Task RunPipelineAsync(IServiceProvider serviceProvider, ICliContext context)
        {
            IReadOnlyCollection <Type> middlewareTypes = context.Configuration.MiddlewareTypes;

            CancellationToken cancellationToken = context.Console.GetCancellationToken();
            CommandPipelineHandlerDelegate next = IMiddlewareExtensions.PipelineTermination;

            foreach (Type middlewareType in middlewareTypes.Reverse())
            {
                IMiddleware instance = (IMiddleware)serviceProvider.GetRequiredService(middlewareType);
                next = instance.Next(context, next, middlewareType, _logger, cancellationToken);
            }

            await next();
        }
Esempio n. 3
0
        public async Task RunPipelineAsync()
        {
            IServiceProvider  serviceProvider = ServiceScope.ServiceProvider;
            LinkedList <Type> middlewareTypes = Context.MiddlewareTypes;

            CancellationToken cancellationToken = Context.Console.GetCancellationToken();
            CommandPipelineHandlerDelegate next = IMiddlewareExtensions.PipelineTermination;

            foreach (Type middlewareType in middlewareTypes)
            {
                IMiddleware instance = (IMiddleware)serviceProvider.GetRequiredService(middlewareType);
                next = instance.Next(Context, next, cancellationToken);
            }

            await next();
        }