Exemplo n.º 1
0
        /// <summary>
        /// 添加Api异常处理服务
        /// </summary>
        /// <param name="services">服务收藏</param>
        /// <param name="options">Api异常处理选项配置</param>
        /// <returns>服务收藏</returns>
        public static IServiceCollection AddApiExceptionHandle(this IServiceCollection services, Action <ApiExceptionHandleOptions> options = null)
        {
            var apiExceptionHandleOptions = new ApiExceptionHandleOptions();

            if (options != null)
            {
                options(apiExceptionHandleOptions);
            }

            services.AddSingleton <IOptions <ApiExceptionHandleOptions> >(provider =>
            {
                return(Options.Create <ApiExceptionHandleOptions>(apiExceptionHandleOptions));
            });

            return(services);
        }
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="next">下一个中间件处理委托</param>
 /// <param name="options">Api异常处理选项配置</param>
 /// <param name="log">日志</param>
 public ApiExceptionHandleMiddleware(RequestDelegate next, IOptions <ApiExceptionHandleOptions> options, ILogable log)
 {
     this.next    = next;
     this.options = options.Value;
     this.log     = log;
 }