示例#1
0
        public void Configuration(IAppBuilder appBuilder)
        {
            ApiAssembie.LoadApiAssembie(ApiConfig.ApiAssemblies);
            var config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();
            //ioc控制反转
            ApiIocConfig.Register(config);
            //启动日志
            LogBuilder.InitLog4Net("WBVV");
            //注册异常过滤器
            config.Filters.Add(new WebApiExceptionFilter());
            //初始化七牛数据
            QiniuData.InitQiniuData();
            //ApiExplorerConfig
            ApiExplorerConfig.Register(config);
            config.Formatters.Clear();
            config.Formatters.Insert(0, new JsonpMediaTypeFormatter());
            var serializerSettings = config.Formatters.JsonFormatter.SerializerSettings;
            var contractResolver   = (DefaultContractResolver)serializerSettings.ContractResolver;

            contractResolver.IgnoreSerializableAttribute = true;
            config.MessageHandlers.Add(new MessageDispatcher());
            config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional });
            appBuilder.UseWebApi(config);
        }
示例#2
0
        public void Configuration(IAppBuilder appBuilder)
        {
            //加载指定的api程序集
            ApiAssembie.LoadApiAssembie(ApiConfig.ApiAssemblies);
            var config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();


            //ioc控制反转
            ApiIocConfig.Register(config);
            //注册异常过滤器
            config.Filters.Add(new WebApiExceptionFilter());
            //ApiExplorerConfig
            ApiExplorerConfig.Register(config);
            //启动日志
            LogBuilder.InitLog4Net("APILog");

            config.Formatters.Clear();
            config.Formatters.Insert(0, new JsonpMediaTypeFormatter());
            var serializerSettings = config.Formatters.JsonFormatter.SerializerSettings;
            var contractResolver   = (DefaultContractResolver)serializerSettings.ContractResolver;

            contractResolver.IgnoreSerializableAttribute = true;
            //异步请求消息
            config.MessageHandlers.Add(new MessageDispatcher());

            //启用跨域
            //GlobalConfiguration.Configuration.EnableCors();
            //config.EnableCors();

            //api的路由设置
            config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional });
            //添加到中间件middleware
            appBuilder.UseWebApi(config);
        }