Пример #1
0
        /// <summary>
        /// Adds the given type as a middleware component for the pipeline executed for this schema type. The middleware component
        /// will be added to the DI collection and created from it.
        /// </summary>
        /// <param name="middlewareInstance">The middleware instance to add to the pipeline.</param>
        /// <param name="name">A friendly, internal name to assign to this component. It will be referenced in any names or log messages that are generated.</param>
        /// <returns>ISchemaConfigurationBuilder.</returns>
        public ISchemaPipelineBuilder <TSchema, TMiddleware, TContext> AddMiddleware(TMiddleware middlewareInstance, string name = null)
        {
            var definition = new GraphMiddlewareDefinition <TContext>(middlewareInstance, name);

            _middleware.AddLast(definition);
            return(this);
        }
Пример #2
0
        /// <summary>
        /// Adds the given Func as a middleware component for this pipeline.
        /// </summary>
        /// <param name="operation"><para>The function to execute in the request pipeline.</para>
        /// <para>Method signature is: The invocation context context, The next delegate in the chain, The cancelation token | Returns a task.</para></param>
        /// <param name="name">A friendly, internal name to assign to this component. It will be referenced in any names or log messages that are generated.</param>
        /// <returns>ISchemaConfigurationBuilder.</returns>
        public ISchemaPipelineBuilder <TSchema, TMiddleware, TContext> AddMiddleware(
            Func <TContext, GraphMiddlewareInvocationDelegate <TContext>, CancellationToken, Task> operation,
            string name = null)
        {
            var middleware = new SingleFunctionMiddleware <TContext>(operation);
            var definition = new GraphMiddlewareDefinition <TContext>(middleware, name);

            _middleware.AddLast(definition);
            return(this);
        }
Пример #3
0
        /// <summary>
        /// Adds the given type as a middleware component for this pipeline.
        /// </summary>
        /// <typeparam name="TComponent">The type of the middlware component.</typeparam>
        /// <param name="lifetime">The life time of the component will determine how often it is recreated or reused
        /// over mulitple invocations..</param>
        /// <param name="name">A friendly, internal name to assign to this component. It will be referenced in any names or log messages that are generated.</param>
        /// <returns>ISchemaConfigurationBuilder.</returns>
        public ISchemaPipelineBuilder <TSchema, TMiddleware, TContext> AddMiddleware <TComponent>(
            ServiceLifetime lifetime = ServiceLifetime.Singleton,
            string name = null)
            where TComponent : class, TMiddleware
        {
            var definition = new GraphMiddlewareDefinition <TContext>(typeof(TComponent), lifetime, name);

            _middleware.AddLast(definition);
            this.TypeReferenceAdded?.Invoke(this, new TypeReferenceEventArgs(typeof(TComponent), lifetime));

            return(this);
        }