コード例 #1
0
ファイル: WebApiConfig.cs プロジェクト: Hermes-7/Practice1
        public static void Register(HttpConfiguration config)
        {
            // Web API 配置和服务

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

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

            //拦截器内部存在需要实例化的对象,交给IOC容器来创建,需要将拦截器加入IOC容器中管理
            UCAuthorizationFilter authorFilter = (UCAuthorizationFilter)GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(UCAuthorizationFilter));

            config.Filters.Add(authorFilter);
        }
コード例 #2
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.Filters.Add(new UCAuthorizationFilter());


            UCAuthorizationFilter authorFilter = (UCAuthorizationFilter)GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(UCAuthorizationFilter));

            config.Filters.Add(authorFilter);
        }
コード例 #3
0
        public static void Register(HttpConfiguration config)
        {
            // Web API 配置和服务

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

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

            //一个对象必须是IOC容器创建出来的,IOC容器才会自动帮我们注入
            //config.Filters.Add(new UCAuthorizationFilter());
            //UCAuthorizationFilter authorFilter = (UCAuthorizationFilter)config.Services.GetService(typeof(UCAuthorizationFilter));
            UCAuthorizationFilter authorFilter = (UCAuthorizationFilter)GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(UCAuthorizationFilter));

            config.Filters.Add(authorFilter);
        }