using Microsoft.AspNetCore.Builder;

namespace HuanMeng.DotNetCore.MiddlewareExtend
{
    /// <summary>
    /// 中间库扩展
    /// </summary>
    public static class MiddlewareExtends
    {
        /// <summary>
        /// 加载全部中间件
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseMiddlewareAll(this IApplicationBuilder builder)
        {
            return builder
                .UseExceptionMiddleware()
                .UseExecutionTimeMiddleware()
                //.SignBaseMiddleware()
                ;

        }

        /// <summary>
        /// 异常中间件
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseExecutionTimeMiddleware(this IApplicationBuilder builder)
        {
            return builder.UseMiddleware<ExecutionTimeMiddleware>();
        }
        /// <summary>
        /// 执行时间中间件
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseExceptionMiddleware(this IApplicationBuilder builder)
        {
            return builder.UseMiddleware<ExceptionMiddleware>();
        }

        /// <summary>
        /// 加密验证
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IApplicationBuilder SignBaseMiddleware(this IApplicationBuilder builder)
        {
            return builder.UseMiddleware<SignBaseMiddleware>();
        }
    }
}
