コード例 #1
0
        internal void Setup(T target, InterceptorOptions options)
        {
            Debug.Assert(this.options == null);

            this.target  = target;
            this.options = options;
        }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: HarinYadav/BoltOn
        public static void Before <TInterceptor>(this InterceptorOptions options)
            where TInterceptor : IInterceptor
        {
            var boltOnOptions        = options.BoltOnOptions;
            var tempInterceptorTypes = boltOnOptions.InterceptorTypes.ToList();

            if (boltOnOptions.RecentlyAddedInterceptor != null)
            {
                var recentlyAddedInterceptor = boltOnOptions.RecentlyAddedInterceptor;
                var tempIndex = tempInterceptorTypes.IndexOf(typeof(TInterceptor));
                if (tempIndex >= 0)
                {
                    tempInterceptorTypes.Remove(recentlyAddedInterceptor);
                    tempInterceptorTypes.Insert(tempIndex, recentlyAddedInterceptor);
                    boltOnOptions.InterceptorTypes = new HashSet <Type>(tempInterceptorTypes);
                }
            }
        }
コード例 #3
0
        public static T CreateInterceptor <T>(
            this InterceptorOptions options,
            T target)
            where T : class
        {
            if (target is null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var proxy = DispatchProxy.Create <T, Interceptor <T> >() as Interceptor <T>;

            proxy !.Setup(target, options);

            return((proxy as T) !);
        }
コード例 #4
0
        public static void After <TInterceptor>(this InterceptorOptions options)
            where TInterceptor : IInterceptor
        {
            var bootstrapperOptions  = options.BootstrapperOptions;
            var tempInterceptorTypes = bootstrapperOptions.InterceptorTypes.ToList();

            if (bootstrapperOptions.RecentlyAddedInterceptor != null)
            {
                var recentlyAddedInterceptor = bootstrapperOptions.RecentlyAddedInterceptor;
                var tempIndex = tempInterceptorTypes.IndexOf(typeof(TInterceptor));
                if (tempIndex >= 0)
                {
                    tempInterceptorTypes.Remove(recentlyAddedInterceptor);
                    if (tempIndex == tempInterceptorTypes.Count)
                    {
                        tempIndex -= 1;
                    }
                    tempInterceptorTypes.Insert(tempIndex + 1, recentlyAddedInterceptor);
                    bootstrapperOptions.InterceptorTypes = new HashSet <Type>(tempInterceptorTypes);
                }
            }
        }
 /// <summary>
 /// 添加从 <see cref="IServiceProvider"/> 中获取的拦截器
 /// </summary>
 /// <typeparam name="TInterceptor"></typeparam>
 /// <param name="options"></param>
 /// <returns></returns>
 public static InterceptorOptions AddServiceInterceptor <TInterceptor>(this InterceptorOptions options) where TInterceptor : IResponseCachingInterceptor
 {
     options.CachingProcessInterceptorTypes.Add(typeof(TInterceptor));
     return(options);
 }
 /// <summary>
 /// 添加拦截器
 /// </summary>
 /// <typeparam name="TInterceptor"></typeparam>
 /// <param name="options"></param>
 /// <param name="interceptor"></param>
 /// <returns></returns>
 public static InterceptorOptions AddInterceptor <TInterceptor>(this InterceptorOptions options, TInterceptor interceptor) where TInterceptor : IResponseCachingInterceptor
 {
     options.CachingProcessInterceptors.Add(interceptor);
     return(options);
 }