Skip to content

Commit fc2fdad

Browse files
authored
Merge pull request #43 from softlgl/dev
修改服务端过滤器属性注入
2 parents 6b29097 + 6cbcf26 commit fc2fdad

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/DotNetCoreRpc.Server/DotNetCoreRpcMiddleware.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ namespace DotNetCoreRpc.Server
1818
public class DotNetCoreRpcMiddleware
1919
{
2020
private readonly RpcServerOptions _rpcServerOptions;
21+
private readonly IServiceProvider _serviceProvider;
2122

22-
public DotNetCoreRpcMiddleware(RequestDelegate next, RpcServerOptions rpcServerOptions)
23+
public DotNetCoreRpcMiddleware(RequestDelegate _, RpcServerOptions rpcServerOptions, IServiceProvider serviceProvider)
2324
{
2425
_rpcServerOptions = rpcServerOptions;
26+
_serviceProvider = serviceProvider;
2527
}
2628

2729
public async Task InvokeAsync(HttpContext context)
@@ -111,7 +113,7 @@ private AspectPiplineBuilder CreatPipleline(RpcContext aspectContext)
111113
await aspectContext.HttpContext.Response.WriteAsync(responseModel.ToJson());
112114
});
113115

114-
List<RpcFilterAttribute> interceptorAttributes = RpcFilterUtils.GetFilterAttributes(aspectContext, _rpcServerOptions.GetFilterTypes());
116+
List<RpcFilterAttribute> interceptorAttributes = RpcFilterUtils.GetFilterAttributes(aspectContext, _serviceProvider, _rpcServerOptions.GetFilterTypes());
115117
if (interceptorAttributes.Any())
116118
{
117119
foreach (var item in interceptorAttributes)

src/DotNetCoreRpc.Server/RpcBuilder/RpcFilterUtils.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class RpcFilterUtils
1717
/// 获取方法filters
1818
/// </summary>
1919
/// <returns></returns>
20-
public static List<RpcFilterAttribute> GetFilterAttributes(RpcContext aspectContext, IEnumerable<Type> filterTypes)
20+
public static List<RpcFilterAttribute> GetFilterAttributes(RpcContext aspectContext, IServiceProvider serviceProvider, IEnumerable<Type> filterTypes)
2121
{
2222
var methondInfo = aspectContext.Method;
2323

@@ -33,13 +33,15 @@ public static List<RpcFilterAttribute> GetFilterAttributes(RpcContext aspectCont
3333
//获取方法filter
3434
methondAttributes.AddRange(classAttributes);
3535
//获取全局filter
36-
var glableInterceptorAttribute = GetInstances(aspectContext.HttpContext.RequestServices, filterTypes);
36+
var glableInterceptorAttribute = GetInstances(serviceProvider, filterTypes);
3737
methondAttributes.AddRange(glableInterceptorAttribute);
38+
39+
//filter属性注入
40+
PropertiesInject(aspectContext.HttpContext.RequestServices, methondAttributes);
41+
3842
return methondAttributes;
3943
});
4044

41-
//filter属性注入
42-
PropertiesInject(aspectContext.HttpContext.RequestServices, methondInterceptorAttributes);
4345
return methondInterceptorAttributes;
4446
}
4547

0 commit comments

Comments
 (0)