/// <summary>
        /// 获取服务行为的特性过滤器   
        /// 并进行属性注入
        /// </summary>
        /// <param name="fastAction">服务行为</param>
        /// <returns></returns>
        public override IEnumerable<IFilter> GetActionFilters(ApiAction fastAction)
        {
            var filters = base.GetActionFilters(fastAction);
            var lifetimeScope = this.dependencyResolver.CurrentLifetimeScope;

            if (lifetimeScope == null)
            {
                return filters;
            }
            return filters.Select(filter => lifetimeScope.InjectProperties(filter));
        }
        /// <summary>
        /// 添加Api行为
        /// </summary>
        /// <param name="apiAction">Api行为</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        public void Add(ApiAction apiAction)
        {
            if (apiAction == null)
            {
                throw new ArgumentNullException("apiAction");
            }

            if (this.dictionary.ContainsKey(apiAction.ApiName))
            {
                throw new ArgumentException(string.Format("Api行为{0}或其命令值已存在", apiAction.ApiName));
            }

            this.CheckSelfParameterType(apiAction);
            this.dictionary.Add(apiAction.ApiName, apiAction);
        }
Beispiel #3
0
 /// <summary>
 /// 获取Api行为的特性过滤器
 /// </summary>
 /// <param name="apiAction">Api行为</param>
 /// <returns></returns>
 public virtual IEnumerable <IFilter> GetActionFilters(ApiAction apiAction)
 {
     return(this.filterCached.GetOrAdd(apiAction, action => GetActionFiltersNoCached(action)));
 }
Beispiel #4
0
 /// <summary>
 /// Api行为上下文
 /// </summary>
 /// <param name="context">请求上下文</param>
 /// <param name="action">Api行为</param>
 public ActionContext(RequestContext context, ApiAction action)
     : base(context.Session, context.Packet, context.AllSessions)
 {
     this.Action = action;
 }
        /// <summary>
        /// 检测参数类型
        /// </summary>
        /// <param name="apiAction">Api行为</param>
        /// <exception cref="ArgumentException"></exception>
        private void CheckSelfParameterType(ApiAction apiAction)
        {
            foreach (var pType in apiAction.ParameterTypes)
            {
                if (pType.IsAbstract || pType.IsInterface)
                {
                    throw new ArgumentException(string.Format("Api{0}的参数类型不能包含抽象类或接口", apiAction.ApiName));
                }

                if (pType.IsSerializable == false)
                {
                    throw new ArgumentException(string.Format("Api{0}的参数类型必须为可序列化", apiAction.ApiName));
                }
            }
        }
 /// <summary>
 /// Api行为上下文
 /// </summary>
 /// <param name="context">请求上下文</param>
 /// <param name="action">Api行为</param>
 public ActionContext(RequestContext context, ApiAction action)
     : base(context.Session, context.Packet, context.AllSessions)
 {
     this.Action = action;
 }