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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        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!
        }
Exemplo n.º 5
0
 /// <summary>
 /// Note: Current middleware is registered automatically.
 /// </summary>
 internal static void UseBotExt(this IPipelineBuilder @this)
 {
     @this.UseMiddleware <ImprovedBotMiddleware>();
 }
Exemplo n.º 6
0
 public static IPipelineBuilder <IEvent> UseMiddleware <TMiddleware>(this IPipelineBuilder <IEvent> pipelineBuilder) where TMiddleware : IPipelineMiddleware <IEvent>
 => pipelineBuilder.UseMiddleware <TMiddleware, IEvent>();
Exemplo n.º 7
0
 public static IPipelineBuilder <MessagingEnvelope> UseTenantMiddleware(this IPipelineBuilder <MessagingEnvelope> pipelineBuilder)
 => pipelineBuilder.UseMiddleware <TenantMiddleware, MessagingEnvelope>();
Exemplo n.º 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>();
Exemplo n.º 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));
 }
Exemplo n.º 10
0
 public static IPipelineBuilder <MessagingContext> UseTenantMiddleware(this IPipelineBuilder <MessagingContext> pipelineBuilder)
 => pipelineBuilder.UseMiddleware <TenantMiddleware, MessagingContext>();
Exemplo n.º 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));
 }
Exemplo n.º 12
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 <MessagingEnvelope> UseMiddleware <TMiddleware>(this IPipelineBuilder <MessagingEnvelope> pipelineBuilder) where TMiddleware : IPipelineMiddleware <MessagingEnvelope>
 => pipelineBuilder.UseMiddleware <TMiddleware, MessagingEnvelope>();
Exemplo n.º 13
0
 public static IPipelineBuilder UseMiddleware <[DynamicallyAccessedMembers(MiddlewareAccessibility)] TMiddleware>(this IPipelineBuilder pipeline) => pipeline.UseMiddleware(typeof(TMiddleware));
Exemplo n.º 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> >();
        }