Example #1
0
        public IDIContainer CreateBuilder(IServiceCollection services)
        {
            //打开框架跟踪日志
            SwitchManager.EnableFrameworkTrace();
            services.AddLogging(cfg =>
            {
                cfg.AddTraceSource("", new DefaultTraceListener());
            }).Configure <LoggerFilterOptions>(option =>
            {
            });

            ContainerManager.Init(services, configureServiceAction: ConfigureServices);
            return(ContainerManager.Container);
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            ContainerFactory.RegisterServices(services);
            services.AddHttpContextAccessor();
            services.AddLogging(cfg =>
            {
                cfg.AddTraceSource("eznew", new DefaultTraceListener());
                cfg.AddFilter("microsoft", LogLevel.Warning);
            });
            SwitchManager.EnableFrameworkTrace();
            services.AddMvc(options =>
            {
                options.ModelValidatorProviders.Add(new CustomDataAnnotationsModelValidatorProvider());
                options.ModelMetadataDetailsProviders.Add(new CustomModelDisplayProvider());
                options.Filters.Add <ExtendAuthorizeFilter>();
                options.Filters.Add <ConsoleExceptionFilter>();
            })
            .AddViewOptions(vo =>
            {
                vo.ClientModelValidatorProviders.Add(new CustomDataAnnotationsClientModelValidatorProvider());
            })
            .AddRazorOptions(ro =>
            {
                ro.ViewLocationExpanders.Add(new FolderLevelViewLocationExpander(typeof(WebBaseController)));
            });
            services.AddAuthentication(options =>
            {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddCookieAuthentication(option =>
            {
                option.ForceValidatePrincipal = true;
                option.ValidatePrincipalAsync = IdentityManager.ValidatePrincipalAsync;
                option.CookieConfiguration    = options =>
                {
                    options.LoginPath        = "/login";
                    options.AccessDeniedPath = "/accessdenied";
                };
            });
            var serviceProvider = ContainerFactory.GetServiceProvider();

            return(serviceProvider);
        }