using Common.Tools;
using djy_AfrApi.Controllers.Common;
using djy_AfrApi.Milldlewares;
using Microsoft.AspNetCore.Builder;
using System.Collections.Generic;
using System.Linq;
namespace djy_AfrApi.Middlewares
{
public static class MiddlewareHelpers
{
///
/// 异常处理
///
public static IApplicationBuilder UseExceptionHandlerMiddle(this IApplicationBuilder app)
{
return app.UseMiddleware();
}
///
/// 处理特殊情况下的响应格式(401、403)
///
public static IApplicationBuilder UseUnifyResultMiddleware(this IApplicationBuilder app)
{
return app.UseMiddleware();
}
///
/// 二次验证授权,并保存当前登录人User对象(为了和ISF、AMS逻辑保持一致)
///
public static IApplicationBuilder UseNextAuthorizationMiddle(this IApplicationBuilder app)
{
return app.UseMiddleware();
}
///
/// 记录请求和响应数据
///
public static IApplicationBuilder UseRequRespLogMiddleware(this IApplicationBuilder app)
{
return app.UseMiddleware();
}
///
/// 公共数据缓存中间件
///
public static IApplicationBuilder UseCommonCacheMiddleware(this IApplicationBuilder app)
{
// 获取CommonController下所有含有RedisCaching特性的方法,并将其缓存从Redis中清空
List actions = typeof(CommonController).GetMethods().Where(m => m.GetCustomAttributes(typeof(Attributes.RedisCachingAttribute), false).Length > 0).ToList();
actions.ForEach(m =>
{
string redisKey = m.Name + "Cache";
YsRedisHelp.Del(redisKey);
});
return app.UseMiddleware();
}
}
}