// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IEventSubscriptionManager eventSubscriptionManager)
        {
            eventSubscriptionManager.Subscribe <PageViewEvent, PageViewEventHandler>();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHealthCheck("/health", serviceProvider =>
            {
                // 检查数据库访问是否正常
                var configuration = serviceProvider.GetService <IConfiguration>();
                var connString    = configuration.GetConnectionString("Configurations");
                using (var conn = new SqlConnection(connString))
                {
                    conn.EnsureOpen();
                }
                return(true);
            });

            app.Use(async(context, next) =>
            {
                var eventPublisher = context.RequestServices.GetRequiredService <IEventPublisher>();
                await eventPublisher.Publish("pageView", new PageViewEvent()
                {
                    Path = context.Request.Path.Value
                });
                await next();
            });
            app.UseAuthentication();
            app.UseMvc();
        }
        public bool Subscribe(Type eventType, Type eventHandlerType)
        {
            var channelName = GetChannelName(eventType, eventHandlerType);

            _subscriber.Subscribe(channelName, async(channel, eventMessage) =>
            {
                var eventData = eventMessage.ToString().ToEvent();
                var handler   = (IEventHandler)_serviceProvider.GetServiceOrCreateInstance(eventHandlerType);
                if (null != handler)
                {
                    await handler.Handle(eventData).ConfigureAwait(false);
                }
            });
            return(_subscriptionManager.Subscribe(eventType, eventHandlerType));
        }
Exemple #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IEventSubscriptionManager eventSubscriptionManager)
        {
            eventSubscriptionManager.Subscribe <PageViewEvent, PageViewEventHandler>();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHealthCheck("/health", serviceProvider =>
            {
                // 检查数据库访问是否正常
                var configuration = serviceProvider.GetService <IConfiguration>();
                var connString    = configuration.GetConnectionString("Configurations");
                using (var conn = new SqlConnection(connString))
                {
                    conn.EnsureOpen();
                }
                return(true);
            });

            //app.Use(async (context, next) =>
            //{
            //    var eventPublisher = context.RequestServices.GetRequiredService<IEventPublisher>();
            //    await eventPublisher.Publish("pageView", new PageViewEvent() { Path = context.Request.Path.Value });
            //    await next();
            //});

            var supportedCultures = new[]
            {
                new CultureInfo("zh"),
                new CultureInfo("en"),
            };

            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("zh"),
                // Formatting numbers, dates, etc.
                SupportedCultures = supportedCultures,
                // UI strings that we have localized.
                SupportedUICultures = supportedCultures
            });

            app.UseAuthentication();
            app.UseMvcWithDefaultRoute();
        }
Exemple #4
0
 public IActionResult Subscribe()
 {
     _eventSubscription.Subscribe <TestEvent, TestEventHandler>();
     return(Ok("add subscribe"));
 }
 public bool Subscribe(Type eventType, Type eventHandlerType) => _subscriptionManager.Subscribe(eventType, eventHandlerType);