// 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) { ILibraryManager libraryManager = app.GetService <ILibraryManager>(); TypeGlobals.LibraryManager = libraryManager; var typeFinder = new TypeFinder(libraryManager); var registrationTypes = TypeHelper <Controller> .FindTypesInAssemblies(TypeHelper <Controller> .IsType).ToList(); List <Type> types = new List <Type>(); foreach (Type type in registrationTypes) { var attrib = type.GetCustomAttributes(typeof(AreaAttribute), true); if (attrib.Length > 0) { RouteConstraintAttribute f = (RouteConstraintAttribute)attrib.First(); types.Add(type); } } var areaTypes = TypeHelper <Controller> .FindTypesWithCustomAttribute <AreaAttribute>(); var assemb = typeFinder.GetLoadedAssemblies(); foreach (var a in assemb) { try { System.Diagnostics.Debug.WriteLine("Assembly:>>" + a.FullName); } catch { } } app.UseMiddleware(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859 try { using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>() .CreateScope()) { serviceScope.ServiceProvider.GetService <ApplicationDbContext>() .Database.Migrate(); } } catch { } } app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); app.UseStaticFiles(); app.UseIdentity(); // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", template: "{area:exists}/{controller}/{action}", defaults: new { action = "Index" }); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); app.Use(async(context, next) => { Console.WriteLine("1"); await next(); Console.WriteLine("8"); }); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { // Add framework services. services.AddEntityFramework() .AddSqlServer() .AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddSingleton <LogFilter>(); services.AddMvc(); services.AddCaching(); // Create the Autofac container builder. // var containerBuilder = new ContainerBuilder(); // Add any Autofac modules or registrations. // containerBuilder.RegisterModule(new AutofacModule()); // return container.Resolve<IServiceProvider>(); services.AddOptions(); services.Configure <FiltersConfig>(Configuration.GetSection("Filters")); // Add application services. services.AddTransient <IEmailSender, AuthMessageSender>(); services.AddTransient <ISmsSender, AuthMessageSender>(); // services.AddSingleton<IFilterProvider, MyFluentFilterProvider>(); services.AddSingleton <IFilterProvider, OverrideFriendlyFilterProvider>(); services.AddSingleton <IConfigurationRoot>(); services.AddSingleton <IConfigurationRoot, GlobalSettings>(); // var sp = services.BuildServiceProvider(); // containerBuilder.Populate(services); // autofac auto registration services.AddDependencies(); var serviceProvider = services.BuildServiceProvider(Configuration); ILibraryManager libraryManager = null; libraryManager = services.GetService <ILibraryManager>(); TypeGlobals.LibraryManager = libraryManager; var dependencyResolver = services.GetService <IDependencyResolver>(); OverrideFriendlyFilterProvider.Configure(Configuration); var typeFinder = new TypeFinder(libraryManager); var registrationTypes = TypeHelper <Controller> .FindTypesInAssemblies(TypeHelper <Controller> .IsType).ToList(); List <Type> types = new List <Type>(); foreach (Type type in registrationTypes) { var attrib = type.GetCustomAttributes(typeof(AreaAttribute), true); if (attrib.Length > 0) { RouteConstraintAttribute f = (RouteConstraintAttribute)attrib.First(); types.Add(type); } } // var container = containerBuilder.Build(); // var sp = container.Resolve<IServiceProvider>(); var authFilter = serviceProvider.GetService(typeof(Pingo.Filters.AuthActionFilter)); var config = serviceProvider.GetService(typeof(IConfigurationRoot)); var global = serviceProvider.GetService <Pingo.Core.Global>(); Pingo.Core.TheApp.Global = global; return(serviceProvider); }