/// <summary>
        /// Register common exception handler chain which is invoked before the ones registered to exception type.
        /// </summary>
        /// <param name="configure">An <see cref="Action{IExceptionHandlerBuilder}"/> to build the exception handler chain.</param>
        /// <returns>The current <see cref="IExceptionPolicyBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="configure"/> is null.</exception>
        public IExceptionPolicyBuilder Pre(Action <IExceptionHandlerBuilder> configure)
        {
            Guard.ArgumentNotNull(configure, nameof(configure));
            ExceptionHandlerBuilder builder = new ExceptionHandlerBuilder(this.ServiceProvider);

            configure(builder);
            _preHanlderBuilder.Use(async context =>
            {
                await builder.Build()(context);
            });
            return(this);
        }
Beispiel #2
0
        /// <summary>
        /// Register common exception handler chain which is invoked before the ones registered to exception type.
        /// </summary>
        /// <param name="predicate">A filter used to determine whether the registered exception handler should be invoked.</param>
        /// <param name="configure">An <see cref="Action{IExceptionHandlerBuilder}"/> to build the exception handler chain.</param>
        /// <returns>The current <see cref="IExceptionPolicyBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="predicate"/> is null.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="configure"/> is null.</exception>
        public IExceptionPolicyBuilder Pre(Func <Exception, bool> predicate, Action <IExceptionHandlerBuilder> configure)
        {
            Guard.ArgumentNotNull(predicate, nameof(predicate));
            Guard.ArgumentNotNull(configure, nameof(configure));
            ExceptionHandlerBuilder builder = new ExceptionHandlerBuilder(this.ServiceProvider);

            configure(builder);
            _preHanlderBuilder.Use(async context =>
            {
                if (predicate(context.Exception))
                {
                    await builder.Build()(context);
                }
            });
            return(this);
        }