public void Use_Arguments_Not_Allow_Null(string builderIndicator, string typeIndicator)
        {
            IInterceptorChainBuilder builder = builderIndicator == null ? null : new InterceptorChainBuilder(new ServiceCollection().BuildServiceProvider());
            Type type = typeIndicator == null ? null : typeof(string);

            Assert.Throws <ArgumentNullException>(() => builder.Use(type, 1));
        }
Beispiel #2
0
        /// <summary>
        /// Register the interceptor of <paramref name="interceptorType"/> to specified interceptor chain builder.
        /// </summary>
        /// <param name="builder">The interceptor chain builder to which the interceptor is registered.</param>
        /// <param name="interceptorType">The interceptor type.</param>
        /// <param name="order">The order for the registered interceptor in the built chain.</param>
        /// <param name="arguments">The non-injected arguments passes to the constructor.</param>
        /// <returns>The interceptor chain builder with registered interceptor.</returns>
        /// <exception cref="ArgumentNullException">The argument <paramref name="builder"/> is null.</exception>
        /// <exception cref="ArgumentNullException">The argument <paramref name="interceptorType"/> is null.</exception>
        public static IInterceptorChainBuilder Use(this IInterceptorChainBuilder builder, Type interceptorType, int order, params object[] arguments)
        {
            Guard.ArgumentNotNull(builder, nameof(builder));
            Guard.ArgumentNotNull(interceptorType, nameof(interceptorType));
            object instance = ActivatorUtilities.CreateInstance(builder.ServiceProvider, interceptorType, arguments);

            InterceptorDelegate interceptor = next =>
            {
                return(async context =>
                {
                    context.Next = next;
                    InvokeDelegate invoker;
                    if (TryGetInvoke(interceptorType, out invoker))
                    {
                        await invoker(instance, context, builder.ServiceProvider);
                    }
                    else
                    {
                        throw new ArgumentException("Invalid interceptor type", "interceptorType");
                    }
                });
            };

            return(builder.Use(interceptor, order));
        }
        /// <summary>
        /// Register the interceptor of <paramref name="interceptorType"/> to specified interceptor chain builder.
        /// </summary>
        /// <param name="builder">The interceptor chain builder to which the interceptor is registered.</param>
        /// <param name="interceptorType">The interceptor type.</param>
        /// <param name="order">The order for the registered interceptor in the built chain.</param>
        /// <param name="arguments">The non-injected arguments passes to the constructor.</param>
        /// <returns>The interceptor chain builder with registered interceptor.</returns>
        /// <exception cref="ArgumentNullException">The argument <paramref name="builder"/> is null.</exception>
        /// <exception cref="ArgumentNullException">The argument <paramref name="interceptorType"/> is null.</exception>
        public static IInterceptorChainBuilder Use(this IInterceptorChainBuilder builder, Type interceptorType, int order, params object[] arguments)
        {
            Guard.ArgumentNotNull(interceptorType, nameof(interceptorType));
            object interceptor = ActivatorUtilities.CreateInstance(builder.ServiceProvider, interceptorType, arguments);

            return(builder.Use(interceptor, order));
        }
Beispiel #4
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <Ergate.Cache.CacheInterceptor>(this.Order,
                                                 this.MaxRetryCount,
                                                 this.RetryIntervalMilliseconds,
                                                 this.IsEnableBreaker,
                                                 this.ExceptionsAllowedBeforeBreaking,
                                                 this.MillisecondsOfBreak,
                                                 this.TimeOutMilliseconds,
                                                 this.CacheTTLMilliseconds);
 }
        public static IInterceptorChainBuilder Use(this IInterceptorChainBuilder builder, Type interceptorType, int order, params object[] arguments)
        {
            InterceptorDelegate interceptor = next => (async context => {
                object[] newArguments = new object[arguments.Length + 1];
                newArguments[0] = next;
                arguments.CopyTo(newArguments, 1);
                object instance = ActivatorUtilities.CreateInstance(builder.ServiceProvider, interceptorType, newArguments);
                InvokeDelegate invoker;
                if (TryGetInvoke(interceptorType, out invoker))
                {
                    await invoker(instance, context, builder.ServiceProvider);
                }
                else
                {
                    throw new ArgumentException("Invalid interceptor type", "interceptorType");
                }
            });

            return(builder.Use(interceptor, order));
        }
        /// <summary>
        /// Register the interceptor to specified interceptor chain builder.
        /// </summary>
        /// <param name="builder">The interceptor chain builder to which the interceptor is registered.</param>
        /// <param name="interceptor">The interceptor.</param>
        /// <param name="order">The order for the registered interceptor in the built chain.</param>
        /// <returns>The interceptor chain builder with registered interceptor.</returns>
        /// <exception cref="ArgumentNullException">The argument <paramref name="builder"/> is null.</exception>
        /// <exception cref="ArgumentNullException">The argument <paramref name="interceptor"/> is null.</exception>
        public static IInterceptorChainBuilder Use(this IInterceptorChainBuilder builder, object interceptor, int order)
        {
            Guard.ArgumentNotNull(builder, nameof(builder));
            Guard.ArgumentNotNull(interceptor, nameof(interceptor));

            InterceptDelegate Intercept(InterceptDelegate next)
            {
                return(async context =>
                {
                    context.Next = next;
                    if (TryGetInvoke(interceptor.GetType(), out var invoker))
                    {
                        await invoker(interceptor, context, builder.ServiceProvider);
                    }
                    else
                    {
                        throw new ArgumentException("Invalid interceptor type", "interceptorType");
                    }
                });
            }

            return(builder.Use(Intercept, order));
        }
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <MemoryCacheInterceptor>(this.Order);
 }
Beispiel #8
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <LoggerInterceptor>(this.Order);
 }
Beispiel #9
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <DecorateInterceptor>(Order);
 }
 /// <summary>
 /// 方法性能監控
 /// </summary>
 /// <param name="bulBuilder"></param>
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <CoreProfileInterception>(Order, StepName ?? "");
 }
Beispiel #11
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use(this, Order);
 }
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <HystrixInterceptor>(Order);
 }
Beispiel #13
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <FoobarAttribute>(Order);
 }
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <ValidationInterceptor>(this.Order);
 }
Beispiel #15
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <FoobarInterceptor>(this.Order, this.Flag);
 }
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <ExceptionHandler>(this.Order, _logCategory);
 }
Beispiel #17
0
 /// <summary>
 /// Register the provided interceptor to the specified interceptor chain builder.
 /// </summary>
 /// <param name="builder">The interceptor chain builder to which the provided interceptor is registered.</param>
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <ExceptionHandlingInterceptor>(this.Order, this.GetExceptionPolicyName());
 }
 public static IInterceptorChainBuilder Use <TInterceptor>(this IInterceptorChainBuilder builder, int order, params object[] arguments)
 {
     return(builder.Use(typeof(TInterceptor), order, arguments));
 }
 /// <summary>
 /// Register the interceptor of <typeparamref name="TInterceptor"/> type to specified interceptor chain builder.
 /// </summary>
 /// <typeparam name="TInterceptor">The interceptor type.</typeparam>
 /// <param name="builder">The interceptor chain builder to which the interceptor is registered.</param>
 /// <param name="order">The order for the registered interceptor in the built chain.</param>
 /// <param name="arguments">The non-injected arguments passes to the constructor.</param>
 /// <returns>The interceptor chain builder with registered interceptor.</returns>
 /// <exception cref="ArgumentNullException">The argument <paramref name="builder"/> is null.</exception>
 public static IInterceptorChainBuilder Use <TInterceptor>(this IInterceptorChainBuilder builder, int order, params object[] arguments)
 {
     Guard.ArgumentNotNull(builder, nameof(builder));
     return(builder.Use(typeof(TInterceptor), order, arguments));
 }
Beispiel #20
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <ArgumentConversionInterceptor>(this.Order);
 }
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <UnitOfWorkInterceptor>(this.Order);
 }
Beispiel #22
0
 public override void Use(IInterceptorChainBuilder builder) => builder.Use <BazInterceptorAttribute>(Order);