/// <summary> /// 获取Api行为的特性过滤器 /// </summary> /// <param name="action">Api行为</param> /// <returns></returns> private static IEnumerable<IFilter> GetActionFiltersNoCached(ApiAction action) { var methodAttributes = action.GetMethodFilterAttributes(); var classAttributes = action.GetClassFilterAttributes() .Where(filter => filter.AllowMultiple || methodAttributes.Any(mFilter => mFilter.TypeId == filter.TypeId) == false); var methodFilters = methodAttributes.Select(fiter => new { Filter = fiter, Level = (fiter is IAuthorizationFilter) ? FilterLevels.Authorization : FilterLevels.Method }); var classFilters = classAttributes.Select(fiter => new { Filter = fiter, Level = (fiter is IAuthorizationFilter) ? FilterLevels.Authorization : FilterLevels.Class }); var filters = classFilters.Concat(methodFilters) .OrderBy(filter => filter.Level) .ThenBy(filter => filter.Filter.Order) .Select(filter => filter.Filter); return filters; }
private IFilter[] GetActionFiltersNoCachedOld(ApiAction apiAction) { var paramtersFilters = apiAction.GetParametersFilterAttributes(); var methodFilters = apiAction.GetMethodFilterAttributes(); var classFilters = apiAction.GetClassFilterAttributes() .Where(cf => cf.AllowMultiple || methodFilters.Any(mf => mf.TypeId == cf.TypeId) == false); var allFilters = paramtersFilters.Concat(methodFilters).Concat(classFilters).OrderBy(f => f.Order).ToArray(); return(allFilters); }
/// <summary> /// 获取服务行为的特性过滤器 /// 并进行属性注入 /// </summary> /// <param name="apiAction">服务行为</param> /// <returns></returns> public IEnumerable <IFilter> GetActionFilters(ApiAction action) { var methodFilters = action.GetMethodFilterAttributes(); var classFilters = action.GetClassFilterAttributes().Where(cf => cf.AllowMultiple || methodFilters.Any(mf => mf.TypeId == cf.TypeId) == false); var filters = methodFilters.Concat(classFilters).OrderBy(f => f.Order); var lifetimeScope = this.dependencyResolver.CurrentLifetimeScope; if (lifetimeScope == null) { return(filters); } return(filters.Select(f => lifetimeScope.InjectProperties(f))); }
/// <summary> /// 获取Api行为的特性过滤器 /// </summary> /// <param name="apiAction">Api行为</param> /// <returns></returns> private IFilter[] GetActionFiltersNoCached(ApiAction apiAction) { var paramtersFilters = apiAction.GetParametersFilterAttributes(); var methodFilters = apiAction.GetMethodFilterAttributes(); var classFilters = apiAction.GetClassFilterAttributes(); var allFilters = paramtersFilters .Concat(methodFilters) .Concat(classFilters) .Distinct(new FilterAttributeComparer()) .OrderBy(f => f.Order) .ToArray(); return(allFilters); }