/// <summary>
        /// Регистрирует тип сообщения
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="provider"></param>
        /// <returns></returns>
        public static IMessageTypeProvider Register <T>(this IMessageTypeProvider provider)
        {
            var type = typeof(T);
            var tag  = AttributeHelper.GetPropertyName <MessageQueueNameAttribute>(type, true);

            return(provider.Register(tag, type));
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              IMessageTypeProvider messageTypeProvider,
                              IOptions <FrameworkConfiguration> frameworkConfigOptions,
                              IMailboxProcessor mailboxProcessor,
                              IApplicationLifetime applicationLifetime)
        {
            applicationLifetime.ApplicationStopping.Register(() =>
            {
                _commandConsumer1?.Stop();
                _commandConsumer2?.Stop();
                _commandConsumer3?.Stop();
                _domainEventProcessor?.Stop();
                _applicationEventProcessor?.Stop();
                _messagePublisher?.Stop();
                _commandBus?.Stop();
                mailboxProcessor.Stop();
            });
            mailboxProcessor.Start();
            messageTypeProvider.Register(new Dictionary <string, string>
            {
                ["Login"] = "******"
            })
            .Register("Modify", typeof(Modify));

            StartMessageQueueComponents();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(new GlobalExceptionHandlerOptions(loggerFactory, env));
            }
            //app.UseMiniProfiler();
            PathBase = Configuration.Instance[nameof(PathBase)];
            app.UsePathBase(PathBase);

            app.Use(next => context =>
            {
                context.Request.Path = context.Request.Path.Value.Replace("//", "/");
                return(next(context));
            });

            app.Use(next => context =>
            {
                context.Request.EnableRewind();
                context.Response.EnableRewind();
                return(next(context));
            });
            //app.Use(async (context, next) =>
            //{
            //    await next();
            //    if (context.Response.StatusCode == StatusCodes.Status404NotFound)
            //    {
            //        context.Request.Path = "/Home/Error";
            //        await next();
            //    }
            //});

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                routes.MapRoute("default",
                                "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseLogLevelController();
            app.UseMessageProcessorDashboardMiddleware();

            var logger = loggerFactory.CreateLogger <Startup>();

            logger.SetMinLevel(LogLevel.Information);
            logger.LogInformation($"Startup configured env: {env.EnvironmentName}");
        }