You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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
{
/// <summary>
/// 异常处理
/// </summary>
public static IApplicationBuilder UseExceptionHandlerMiddle ( this IApplicationBuilder app )
{
return app . UseMiddleware < ExceptionHandlerMiddleware > ( ) ;
}
/// <summary>
/// 处理特殊情况下的响应格式( 401、403)
/// </summary>
public static IApplicationBuilder UseUnifyResultMiddleware ( this IApplicationBuilder app )
{
return app . UseMiddleware < UnifyResultMiddleware > ( ) ;
}
/// <summary>
/// 二次验证授权, 并保存当前登录人User对象( 为了和ISF、AMS逻辑保持一致)
/// </summary>
public static IApplicationBuilder UseNextAuthorizationMiddle ( this IApplicationBuilder app )
{
return app . UseMiddleware < NextAuthorizationMiddleware > ( ) ;
}
/// <summary>
/// 记录请求和响应数据
/// </summary>
public static IApplicationBuilder UseRequRespLogMiddleware ( this IApplicationBuilder app )
{
return app . UseMiddleware < RequRespLogMiddleware > ( ) ;
}
/// <summary>
/// 公共数据缓存中间件
/// </summary>
public static IApplicationBuilder UseCommonCacheMiddleware ( this IApplicationBuilder app )
{
// 获取CommonController下所有含有RedisCaching特性的方法, 并将其缓存从Redis中清空
List < System . Reflection . MethodInfo > 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 < CommonDataCacheMiddleware > ( ) ;
}
}
}