Exemple #1
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));
        }
        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));
        }
Exemple #4
0
        /// <summary>
        /// Create a new <see cref="ProxyFactory"/>.
        /// </summary>
        /// <param name="serviceProvider">The service provider to get dependent services.</param>
        /// <param name="builder">The interceptor chain builder.</param>
        /// <exception cref="ArgumentNullException">The argument <paramref name="serviceProvider"/> is null.</exception>
        /// <exception cref="ArgumentNullException">The argument <paramref name="builder"/> is null.</exception>
        public ProxyFactory(IServiceProvider serviceProvider, IInterceptorChainBuilder builder)
        {
            Guard.ArgumentNotNull(serviceProvider, nameof(serviceProvider));
            Guard.ArgumentNotNull(builder, nameof(builder));

            this.ServiceProvider = serviceProvider;
            this.Builder         = builder;
        }
Exemple #5
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));
        }
 /// <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 abstract void Use(IInterceptorChainBuilder builder);
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <HystrixInterceptor>(Order);
 }
Exemple #10
0
 public ProxyFactory(IServiceProvider serviceProvider, IInterceptorChainBuilder builder)
 {
     this.ServiceProvider = serviceProvider;
     this.Builder         = builder;
 }
Exemple #11
0
 public InterceptorFactory(IInterceptorChainBuilder chainBuilder, IProxyGenerator proxyGenerator, IInterceptBuilder interceptBuilder)
 {
     _chainBuilder     = chainBuilder;
     _proxyGenerator   = proxyGenerator;
     _interceptBuilder = interceptBuilder;
 }
Exemple #12
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <FoobarInterceptor>(this.Order, this.Flag);
 }
Exemple #13
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use(this, Order);
 }
Exemple #14
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <DecorateInterceptor>(Order);
 }
Exemple #15
0
 public DynamicProxyFactory(IServiceProvider serviceProvider, IInterceptorChainBuilder builder) : base(serviceProvider, builder)
 {
     _proxyGenerator = new ProxyGenerator();
 }
Exemple #16
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());
 }
 /// <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));
 }
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <ExceptionHandler>(this.Order, _logCategory);
 }
Exemple #19
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <ArgumentConversionInterceptor>(this.Order);
 }
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <UnitOfWorkInterceptor>(this.Order);
 }
 public static IInterceptorChainBuilder Use <TInterceptor>(this IInterceptorChainBuilder builder, int order, params object[] arguments)
 {
     return(builder.Use(typeof(TInterceptor), order, arguments));
 }
Exemple #22
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <FoobarAttribute>(Order);
 }
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <ValidationInterceptor>(this.Order);
 }
 /// <summary>
 /// 方法性能監控
 /// </summary>
 /// <param name="bulBuilder"></param>
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <CoreProfileInterception>(Order, StepName ?? "");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="InterceptorCollector"/> class.
 /// </summary>
 /// <param name="builder">The builder.</param>
 public InterceptorCollector(IInterceptorChainBuilder builder)
 {
     this.Builder = Guard.ArgumentNotNull(builder, nameof(builder));
 }
Exemple #26
0
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <LoggerInterceptor>(this.Order);
 }
 public override void Use(IInterceptorChainBuilder builder)
 {
     throw new NotImplementedException();
 }
 public override void Use(IInterceptorChainBuilder builder)
 {
     builder.Use <MemoryCacheInterceptor>(this.Order);
 }
Exemple #29
0
 public override void Use(IInterceptorChainBuilder builder) => builder.Use <BazInterceptorAttribute>(Order);