Beispiel #1
0
        void Application_Start(object sender, EventArgs e)
        {
            // 在应用程序启动时运行的代码
//            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
//            RouteConfig.RegisterRoutes(RouteTable.Routes);
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

            #region IOC配置

            //DI配置
            var initialize = new InitializeContainer();
            initialize.Initializing();
            //WebAPI
            GlobalConfiguration.Configuration.DependencyResolver =
                new AutofacWebApiDependencyResolver(initialize.ContainerManager.Container);

            //MVC
            DependencyResolver.SetResolver(new AutofacDependencyResolver(initialize.ContainerManager.Container));

            #endregion


            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Beispiel #2
0
        public static void Register(HttpConfiguration config)
        {
            //允许跨域请求
            config.EnableCors();

            //DI配置
            var initialize = new InitializeContainer();

            initialize.Initializing();
            //TODO:实现自己的Resolver,未实现前暂时使用Auto自带的
            config.DependencyResolver = new AutofacWebApiDependencyResolver(initialize.ContainerManager.Container);


            //filter
            //config.Filters.Add((IFilter)config.DependencyResolver.GetService(typeof(YpAPIHandleErrorAttribute)));
            //config.Filters.Add((IFilter)config.DependencyResolver.GetService(typeof(YpAPIAuthorizeAttribute)));
            #region 路由配置
            // Web API 路由
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
            #endregion
        }
Beispiel #3
0
        public static void Register(HttpConfiguration config)
        {
            // Web API 配置和服务

            // Web API 路由
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.EnableCors();

            //DI配置
            var initialize = new InitializeContainer();

            initialize.Initializing();
            //TODO:实现自己的Resolver,未实现前暂时使用Auto自带的
            config.DependencyResolver = new AutofacWebApiDependencyResolver(initialize.ContainerManager.Container);

//            var jsonFormatter = new JsonMediaTypeFormatter();
//            var settings = jsonFormatter.SerializerSettings;
//            IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
//            //这里使用自定义日期格式
//            timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
//            settings.Converters.Add(timeConverter);
        }
Beispiel #4
0
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            #region IOC配置

            //DI配置
            var initialize = new InitializeContainer();
            initialize.Initializing();
            //WebAPI
            GlobalConfiguration.Configuration.DependencyResolver =
                new AutofacWebApiDependencyResolver(initialize.ContainerManager.Container);

            //MVC
            DependencyResolver.SetResolver(new AutofacDependencyResolver(initialize.ContainerManager.Container));

            #endregion
        }
Beispiel #5
0
        protected void Application_Start(object sender, EventArgs e)
        {
            //注册依赖容器
            var initialize = new InitializeContainer();

            initialize.Initializing();

            var resolver = new YpDependencyResolver(initialize);

            DependencyResolver.SetResolver(resolver);

            //注册全局Filter
            //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            AreaRegistration.RegisterAllAreas();

            GlobalConfiguration.Configuration.EnableCors();
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(initialize.ContainerManager.Container);
            GlobalConfiguration.Configure(WebApiConfig.Register);

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
        }