asp.netcore 获取中间件列表
2023-04-18 22:37 qgbo 阅读(38) 评论(0) 编辑 收藏 举报
var applicationBuilderInfo = app.GetType().GetProperty("ApplicationBuilder", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase); var _componentsInfo = typeof(ApplicationBuilder).GetField("_components", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase); var applicationBuilder = applicationBuilderInfo.GetValue(app); var midds= _componentsInfo.GetValue(applicationBuilder) as List<Func<RequestDelegate, RequestDelegate>>; foreach (var x in midds) { }
这是基于dotnet7
var app = builder.Build();
builder.use 的时候,会给app.ApplicationBuilder._components 这个属性add 一个 Func<RequestDelegate, RequestDelegate>
ApplicationBuilder 和 _components 都是pravite, so 需要用反射得到
只是能看到有几个而已。具体源码怎么写的已经看不到了
气功波(18037675651)