Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }



            Container.GetFacility <AspNetCoreFacility>().RegistersMiddlewareInto(app);

            // Add custom middleware, do this if your middleware uses DI from Windsor

            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Article}/{action=Index}/{id?}");
            });
        }
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, ILogger <Startup> loggerFactory, IHttpContextAccessor httpContextAccessor)
        {
            // For making component registrations of middleware easier
            _container.GetFacility <AspNetCoreFacility>().RegistersMiddlewareInto(app);

            // Controller middleware resolve dependant service type 1
            //var entityService = _container.Resolve<ISampleEntityService>();
            //if (entityService != null)
            //{
            //    _container.Register(Component.For<ResolveControllerDependenciesMiddleware>()
            //                                    .DependsOn(Dependency.OnValue<ILoggerFactory>(loggerFactory))
            //                                    .DependsOn(Dependency.OnValue<ISampleEntityService>(entityService))
            //                                    .LifestyleTransient()
            //                                    .AsMiddleware());
            //}

            // Add framework configured middleware, use this if you dont have any DI requirements
            //app.UseMiddleware<FrameworkMiddleware>();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseWhen(context => !context.Request.Path.StartsWithSegments("/Identity"), appBuilder => {
                appBuilder.UseMiddleware <ResponseMeasurementMiddleware>();
            });

            // Controller middleware resolve dependant service type 2
            //app.Use(async(ctx,next) =>
            //{
            //    loggerFactory.LogInformation($"middleware to provide/resolve required dependent service for controller");
            //    var SampleService = _container.Resolve<ISampleEntityService>(); //ctx.RequestServices.GetService<ISampleEntityService>();
            //    await next();
            //});

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app">
        /// The app.
        /// </param>
        /// <param name="env">
        /// The env.
        /// </param>
        /// /// <param name="loggerFactory">
        /// The logger factory.
        /// </param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            Container.GetFacility <AspNetCoreFacility>().RegistersMiddlewareInto(app);
            loggerFactory.AddLog4Net();
            app.UseCors("CorsPolicy");
            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/TravianManager/swagger.json", "Packing API");
            });
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // Windsor setups...
            Container.GetFacility <AspNetCoreFacility>().RegistersMiddlewareInto(app);

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

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseEndpoints(builder =>
            {
                builder.MapControllers();
            });
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            Container.GetFacility <AspNetCoreFacility>().RegistersMiddlewareInto(app);

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc();
        }
Ejemplo n.º 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            var applicationLifetime = app.ApplicationServices.GetRequiredService <IApplicationLifetime>();

            applicationLifetime.ApplicationStopping.Register(OnShutdown);

            _windsorContainer.GetFacility <AspNetCoreFacility>().RegistersMiddlewareInto(app);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error/Error");
            }

            var unitOfWorkMode = AppSettings.Configuration["UnitOfWorkMode"];

            switch (unitOfWorkMode)
            {
            case "TransactionScopeUnitOfWork":
                _setupTransactionScopeUnitOfWork();
                break;

            case "UnitOfWork":
                _setupUnitOfWorkWithDelayedDomainEventHandling();
                break;

            default:
                throw new NotSupportedException("Unsupported unit of work mode.");
            }

            var pathBase = AppSettings.Configuration["PathBase"];

            if (!string.IsNullOrWhiteSpace(pathBase))
            {
                app.UsePathBase(pathBase);
            }

            app.UseStaticFiles();

            app.UseAuthentication();

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

            _ConfigureBus(_windsorContainer);
            _UpgradeDatabase();

            void _setupTransactionScopeUnitOfWork()
            {
                _windsorContainer.Register(
                    Component.For <TransactionScopeUnitOfWorkMiddleware>()
                    .DependsOn(Dependency.OnValue <System.Transactions.IsolationLevel>(
                                   System.Transactions.IsolationLevel.ReadCommitted
                                   ))
                    .DependsOn(Dependency.OnValue <Action <System.Transactions.TransactionScope> >(
                                   (Action <System.Transactions.TransactionScope>)(transactionScope => transactionScope.EnlistRebus())
                                   ))
                    .LifestyleSingleton().AsMiddleware()
                    );

                DomainEvents.Initialize(_windsorContainer.Resolve <IDomainEventHandlerFactory>());
            }

            void _setupUnitOfWorkWithDelayedDomainEventHandling()
            {
                _windsorContainer.Register(
                    Component.For <UnitOfWorkMiddleware>()
                    .DependsOn(Dependency.OnValue <IsolationLevel>(IsolationLevel.ReadCommitted))
                    .LifestyleSingleton().AsMiddleware()
                    );

                DomainEvents.Initialize(
                    _windsorContainer.Resolve <IDomainEventHandlerFactory>(),
                    isDelayedDomainEventHandlingEnabled: true
                    );
            }
        }