/// <summary>
        /// 获取服务实例
        /// </summary>
        /// <typeparam name="TService">服务类型</typeparam>
        /// <param name="request">request</param>
        /// <returns>服务实例</returns>
        public static TService GetService <TService>(this HttpRequestMessage request)
        {
            System.Web.Http.Dependencies.IDependencyScope dependencyScope = request.GetDependencyScope();
            TService service = (TService)dependencyScope.GetService(typeof(TService));

            return(service);
        }
示例#2
0
 public static T GetService <T>(this System.Web.Http.Dependencies.IDependencyScope scope)
 {
     return((T)scope.GetService(typeof(T)));
 }