public static IServiceCollection AddPipeline <TOut>(
            this IServiceCollection services,
            Func <HttpContext, TOut, Task> parseResponse)
        {
            var instructions = new PipelineInstructions <TOut>(
                WrapParseResponse(parseResponse)
                );

            services.AddSingleton(instructions);

            return(services);
        }
        public static IServiceCollection AddPipeline <TIn, TOut>(
            this IServiceCollection services,
            Func <HttpContext, Task <TIn> > parseModel,
            Func <HttpContext, PipelineResponse <TOut>, Task> parseResponse)
        {
            var instructions = new PipelineInstructions <TIn, TOut>(
                parseModel, parseResponse
                );

            services.AddSingleton(instructions);

            return(services);
        }
        private static async Task TryRunPipeline <TIn, TOut>(
            IServiceProvider sp,
            PipelineInstructions <TIn, TOut> instructions,
            IRetriever <TIn, TOut> retriever,
            HttpContext context)
        {
            var(pipeline, ok) = instructions.TryGetPipeline <TIn, TOut>(sp);
            if (!ok)
            {
                throw new Exception("Could not create pipeline");
            }

            await pipeline.Run(retriever, context);
        }
Exemple #4
0
        public void CanCreatePipeline()
        {
            // Arrange
            var instructions = new PipelineInstructions <ModelRequest, ModelResponse>(
                ModelParser.FromBody,
                ModelParser.SetFromModelResponse);

            var services = new ServiceCollection();
            var sp       = services.BuildServiceProvider();

            // Act
            var(pipeline, ok) = instructions.TryGetPipeline <ModelRequest, ModelResponse>(sp);

            // Assert
            Assert.True(ok);
            Assert.NotNull(pipeline);
        }
        public static IServiceCollection AddPipeline <TIn, TOut>(
            this IServiceCollection services,
            Func <HttpContext, TIn> parseModel,
            Func <HttpContext, PipelineResponse <TOut>, Task> parseResponse,
            Action <PipelineInstructions <TIn, TOut> > builder = null)
        {
            var instructions = new PipelineInstructions <TIn, TOut>(
                parseModel, parseResponse
                );

            if (builder != null)
            {
                builder(instructions);
            }

            services.AddSingleton(instructions);

            return(services);
        }
Exemple #6
0
        public void CanBuildMiddleware()
        {
            // Arrange
            var instructions = new PipelineInstructions <ModelRequest, ModelResponse>(
                ModelParser.FromBody,
                ModelParser.SetFromModelResponse)
                               .WithMiddleware <TimingMiddleware>();

            var services = new ServiceCollection();

            services.AddTransient <TimingMiddleware>();
            var sp = services.BuildServiceProvider();

            // Act
            var middleware = instructions.BuildMiddleware(sp);

            // Assert
            Assert.NotNull(middleware);
        }