Beispiel #1
0
        protected void Application_Start()
        {
            var config = GlobalConfiguration.Configuration;

            config.DependencyResolver = new AutofacWebApiDependencyResolver(DIRegister.RegisterTypes());

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //设置数据库连接字符串
            DbContexts.EFDbFactory.ConnectionString = Configuration.GetSection("connection")["mysql"];

            //原core原生依赖注入配置
            DIRegister sdr = new DIRegister();

            sdr.DIRegister_Context(services);

            //解决中文被编码
            services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));

            //配置时间格式
            services.AddMvc(opt =>
            {
                opt.RespectBrowserAcceptHeader = true;
                opt.Filters.Add <ExceptionFilterAttribute>();
                opt.Filters.Add <PermissionsAttribute>();
                opt.Filters.Add <GlobalActionFilterAttribute>();
            })
            .AddJsonOptions(options =>
            {
                //设置时间格式
                options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            #region 使用autofac代替原生IOC
            //ContainerBuilder builder = new ContainerBuilder();
            ////将services中的服务填充到Autofac中.
            //builder.Populate(services);
            ////新模块组件注册
            //builder.RegisterModule<DefaultModuleRegister>();
            ////创建容器.
            //AutofacContainer = builder.Build();
            ////使用容器创建 AutofacServiceProvider
            //return new AutofacServiceProvider(AutofacContainer);
            #endregion
        }