コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="predicate">A predicate to indicate whether to invoke the registered handler.</param>
        /// <param name="configuration"></param>
        public override void Use(IExceptionHandlerBuilder builder, Func <ExceptionContext, bool> predicate, IDictionary <string, string> configuration)
        {
            Guard.ArgumentNotNull(builder, nameof(builder));
            Guard.ArgumentNotNull(configuration, nameof(configuration));
            Type   wrapExcecptionType = Type.GetType(configuration.GetValue(ConfigurationNameOfWrapException));
            string message            = configuration.GetValue(ConfigurationNameOfMessage);

            builder.Use <WrapHandler>(wrapExcecptionType, predicate, message);
        }
コード例 #2
0
        public void Use_Arguments_Not_Allow_Null(string builderIndicator, string typeIndicator)
        {
            IExceptionHandlerBuilder builder = builderIndicator == null
                ? null
                : new ExceptionHandlerBuilder(new ServiceCollection().BuildServiceProvider());
            Type type = typeIndicator == null
                ? null
                : typeof(string);

            Assert.Throws <ArgumentNullException>(() => builder.Use(type));
        }
コード例 #3
0
        /// <summary>
        /// Register specified type of exception handler to <see cref="IExceptionHandlerBuilder"/>.
        /// </summary>
        /// <param name="handlerType">The type of exception handler to register.</param>
        /// <param name="builder">The <see cref="IExceptionHandlerBuilder"/> to which the exception handler is registered.</param>
        /// <param name="arguments">The arguments passed to constrcutors.</param>
        /// <returns>The current <see cref="IExceptionHandlerBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="builder"/> is null.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="handlerType"/> is null.</exception>
        public static IExceptionHandlerBuilder Use(this IExceptionHandlerBuilder builder, Type handlerType, params object[] arguments)
        {
            Guard.ArgumentNotNull(builder, nameof(builder));
            Guard.ArgumentNotNull(handlerType, nameof(handlerType));

            if (!TryGetInvoke(handlerType, out HandleExceptionDelegate handlerDelegate))
            {
                throw new ArgumentException("Invalid exception handler type", nameof(handlerType));
            }

            Func <ExceptionContext, Task> handler = async context =>
            {
                object[] newArguments = new object[arguments.Length];
                arguments.CopyTo(newArguments, 0);
                object instance = ActivatorUtilities.CreateInstance(builder.ServiceProvider, handlerType, newArguments);
                await handlerDelegate(instance, context, builder.ServiceProvider);
            };

            return(builder.Use(handler));
        }
コード例 #4
0
 /// <summary>
 /// Register specified type of exception handler to <see cref="IExceptionHandlerBuilder"/>.
 /// </summary>
 /// <param name="handlerType">The type of exception handler to register.</param>
 /// <param name="builder">The <see cref="IExceptionHandlerBuilder"/> to which the exception handler is registered.</param>
 /// <param name="arguments">The arguments passed to constrcutors.</param>
 /// <returns>The current <see cref="IExceptionHandlerBuilder"/>.</returns>
 /// <exception cref="ArgumentNullException">The <paramref name="builder"/> is null.</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="handlerType"/> is null.</exception>
 public static IExceptionHandlerBuilder Use(this IExceptionHandlerBuilder builder, Type handlerType, params object[] arguments)
 {
     return(builder.Use(_ => true, handlerType, arguments));
 }
コード例 #5
0
 /// <summary>
 /// Register specified type of exception handler to <see cref="IExceptionHandlerBuilder"/>.
 /// </summary>
 /// <typeparam name="THandler">The type of exception handler to register.</typeparam>
 /// <param name="builder">The <see cref="IExceptionHandlerBuilder"/> to which the exception handler is registered.</param>
 /// <param name="predicate">A predicate to indicate whether to invoke the registered handler.</param>
 /// <param name="arguments">The arguments passed to constrcutors.</param>
 /// <returns>The current <see cref="IExceptionHandlerBuilder"/>.</returns>
 /// <exception cref="ArgumentNullException">The <paramref name="builder"/> is null.</exception>
 public static IExceptionHandlerBuilder Use <THandler>(this IExceptionHandlerBuilder builder, Func <ExceptionContext, bool> predicate, params object[] arguments)
 {
     return(builder.Use(typeof(THandler), predicate, arguments));
 }
コード例 #6
0
 /// <summary>
 /// Register specified type of exception handler to <see cref="IExceptionHandlerBuilder"/>.
 /// </summary>
 /// <typeparam name="THandler">The type of exception handler to register.</typeparam>
 /// <param name="builder">The <see cref="IExceptionHandlerBuilder"/> to which the exception handler is registered.</param>
 /// <param name="arguments">The arguments passed to constrcutors.</param>
 /// <returns>The current <see cref="IExceptionHandlerBuilder"/>.</returns>
 /// <exception cref="ArgumentNullException">The <paramref name="builder"/> is null.</exception>
 public static IExceptionHandlerBuilder Use <THandler>(this IExceptionHandlerBuilder builder, params object[] arguments)
 {
     Guard.ArgumentNotNull(builder, nameof(builder));
     return(builder.Use(typeof(THandler), arguments));
 }
コード例 #7
0
 /// <summary>
 /// Register the specific exception handler based on configuration.
 /// </summary>
 /// <param name="predicate">A predicate to indicate whether to invoke the registered handler.</param>
 /// <param name="builder">The <see cref="IExceptionHandlerBuilder"/> used to register the specific exception handler.</param>
 /// <param name="configuration">A <see cref="IDictionary{String, String}"/> storing configuration for the exception handler to register.</param>
 public abstract void Use(IExceptionHandlerBuilder builder, Func <ExceptionContext, bool> predicate, IDictionary <string, string> configuration);
コード例 #8
0
 public override void Use(IExceptionHandlerBuilder builder, Func <ExceptionContext, bool> predicate, IDictionary <string, string> configuration)
 {
     this.Use <Handler4>(builder, predicate, configuration);
 }
コード例 #9
0
 protected void Use <THandler>(IExceptionHandlerBuilder builder, Func <ExceptionContext, bool> predicate, IDictionary <string, string> configuration)
     where THandler : HandlerBase
 {
     builder.Use <THandler>(configuration.GetValue("arg1"), configuration.GetValue("arg2"));
 }