public static void UseMvc(
            this IPipelineBuilder @this,
            Action <IUseMvcBuilder> configureUseMvcBuilder = null)
        {
            var addMvcBuilder = @this.ServiceProvider.GetRequiredService <IAddMvcBuilder>();
            var options       = addMvcBuilder.MvcOptions;
            var useMvcBuilder = new UseMvcBuilder(@this.ServiceProvider);

            useMvcBuilder.Controllers = addMvcBuilder.Controllers;
            //Controllers settiongs.
            ControllersMiddlewareExtensions.InitUseMvcBuilder(useMvcBuilder);

            //Custom settings.
            //!Warning! Service bus will always return null values before we init MvcMiddleware.
            configureUseMvcBuilder?.Invoke(useMvcBuilder);

            var md = new MvcMiddleware(addMvcBuilder.MvcOptions, useMvcBuilder);

            //Add BotExt validator.
            if (options.ConfigureBotExtWithMvc)
            {
                @this.AddBotExtMvcGlobalValidator(
                    options.BotExtOrder,
                    md.SetGlobalSearchBag
                    );
            }

            @this.UseMiddleware(md);
        }
        /// <summary>
        /// Resolves middleware form ServiceProvider and use it.
        /// </summary>
        public static void UseMiddleware <TMiddleware>(this IPipelineBuilder @this)
            where TMiddleware : IMiddleware
        {
            var md = @this.ServiceProvider.GetRequiredService <TMiddleware>();

            @this.UseMiddleware(md);
        }
        /// <summary>
        /// 初始化中间件
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        private static IPipelineBuilder InitPipeline(this IPipelineBuilder builder)
        {
            var logger = builder.ApplicationServices.GetRequiredService <ICustomLogger>();

            builder.UseMiddleware <LoggerMiddlewate>(logger);

            builder.UseMiddleware <ResponderMiddleware>(logger);

            builder.UseMiddleware <RouteFinderMiddleware>();

            builder.UseMiddleware <AuthorizationMiddleware>();

            builder.UseMiddleware <RequesterMiddleware>();

            return(builder);
        }
        public void ConfigurePipeline(IPipelineBuilder pipe)
        {
            // Middleware type example - terminal if the message is empty
            pipe.UseMiddleware <ExampleMiddleware>();

            // Raw delegate examples below, but recommendation is Middleware classes
            // since they support dependency injection

            // wrap the next components with this bit of middleware:
            pipe.Use(WrappingExample);

            // Optional terminal example - passes along if a condition passes
            pipe.Use(FilteringExample);

            // Run adds terminal middleware - won't pass on the context any further
            pipe.Run(TerminalExample);

            // Any middleware here (after the Run) will never be invoked!
        }
Beispiel #5
0
 /// <summary>
 /// Note: Current middleware is registered automatically.
 /// </summary>
 internal static void UseBotExt(this IPipelineBuilder @this)
 {
     @this.UseMiddleware <ImprovedBotMiddleware>();
 }
Beispiel #6
0
 public static IPipelineBuilder <IEvent> UseMiddleware <TMiddleware>(this IPipelineBuilder <IEvent> pipelineBuilder) where TMiddleware : IPipelineMiddleware <IEvent>
 => pipelineBuilder.UseMiddleware <TMiddleware, IEvent>();
Beispiel #7
0
 public static IPipelineBuilder <MessagingEnvelope> UseTenantMiddleware(this IPipelineBuilder <MessagingEnvelope> pipelineBuilder)
 => pipelineBuilder.UseMiddleware <TenantMiddleware, MessagingEnvelope>();
Beispiel #8
0
 /// <summary>
 /// Adds the a middleware of type <typeparamref name="TMiddleware"/> to the message processing pipeline.
 /// </summary>
 /// <typeparam name="TMiddleware">The type of the middleware.</typeparam>
 /// <param name="pipelineBuilder">The pipeline builder.</param>
 /// <returns>The pipeline builder for further configuring the pipeline. It is used used in the fluent configuration API.</returns>
 public static IPipelineBuilder <MessagingContext> UseMiddleware <TMiddleware>(this IPipelineBuilder <MessagingContext> pipelineBuilder) where TMiddleware : IPipelineMiddleware <MessagingContext>
 => pipelineBuilder.UseMiddleware <TMiddleware, MessagingContext>();
Beispiel #9
0
 /// <summary>
 /// Adds a middleware type to the application's request pipeline.
 /// </summary>
 /// <typeparam name="TMiddleware">The middleware type.</typeparam>
 /// <param name="app">The <see cref="IApplicationBuilder"/> instance.</param>
 /// <param name="args">The arguments to pass to the middleware type instance's constructor.</param>
 /// <returns>The <see cref="IApplicationBuilder"/> instance.</returns>
 public static IPipelineBuilder UseMiddleware <TMiddleware>(this IPipelineBuilder app, params object[] args)
 {
     return(app.UseMiddleware(typeof(TMiddleware), args));
 }
Beispiel #10
0
 public static IPipelineBuilder <MessagingContext> UseTenantMiddleware(this IPipelineBuilder <MessagingContext> pipelineBuilder)
 => pipelineBuilder.UseMiddleware <TenantMiddleware, MessagingContext>();
Beispiel #11
0
 /// <summary>
 /// Adds a middleware type to the application's request pipeline.
 /// </summary>
 /// <typeparam name="TMiddleware">The middleware type.</typeparam>
 /// <param name="app">The <see cref="IPipelineBuilder"/> instance.</param>
 /// <param name="args">The arguments to pass to the middleware type instance's constructor.</param>
 /// <returns>The <see cref="IPipelineBuilder"/> instance.</returns>
 public static IPipelineBuilder <TService, TContext> UseMiddleware <TMiddleware, TService, TContext>(this IPipelineBuilder <TService, TContext> app, params object[] args)
     where TService : BaseDomainService
     where TContext : IRequestContext
 {
     return(app.UseMiddleware(typeof(TMiddleware), args));
 }
 /// <summary>
 /// Adds the a middleware of type <typeparamref name="TMiddleware"/> to the message processing pipeline.
 /// </summary>
 /// <typeparam name="TMiddleware">The type of the middleware.</typeparam>
 /// <param name="pipelineBuilder">The pipeline builder.</param>
 /// <returns>The pipeline builder for further configuring the pipeline. It is used used in the fluent configuration API.</returns>
 public static IPipelineBuilder <MessagingEnvelope> UseMiddleware <TMiddleware>(this IPipelineBuilder <MessagingEnvelope> pipelineBuilder) where TMiddleware : IPipelineMiddleware <MessagingEnvelope>
 => pipelineBuilder.UseMiddleware <TMiddleware, MessagingEnvelope>();
Beispiel #13
0
 public static IPipelineBuilder UseMiddleware <[DynamicallyAccessedMembers(MiddlewareAccessibility)] TMiddleware>(this IPipelineBuilder pipeline) => pipeline.UseMiddleware(typeof(TMiddleware));
Beispiel #14
0
        // BrokerUrls, ConsumerGroupId, Topics from BasicConsumerConfig
        // are set from appsettings.json or appsettings.{Environment}.json
        // Alternatively from environment variables:
        //
        // Simple strings:
        //         SimpleKafkaConfig__BrokerUrls
        //         SimpleKafkaConfig__ConsumerGroupId
        // Arrays:
        //         SimpleKafkaConfig__Topics__0
        //         [SimpleKafkaConfig__Topics__1]
        //
        // Note: SimpleKafkaConfig as the prefix is from the appsettings.json parent property, used in the call to
        // AddKafkaConsumer from the Startup class
        //
        // See:
        //   - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/index?view=aspnetcore-2.1
        //   - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-2.1

        public override void ConfigurePipeline(IPipelineBuilder pipe)
        {
            pipe.UseMiddleware <ExampleMiddleware <Ignore, string> >();
        }