Open yiyungent opened 3 years ago
using System; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using PluginCore.IPlugins; namespace WebSocketDemoPlugin { public class WebSocketDemoPlugin : BasePlugin, IStartupXPlugin { public override (bool IsSuccess, string Message) AfterEnable() { Console.WriteLine($"{nameof(WebSocketDemoPlugin)}: {nameof(AfterEnable)}"); return base.AfterEnable(); } public override (bool IsSuccess, string Message) BeforeDisable() { Console.WriteLine($"{nameof(WebSocketDemoPlugin)}: {nameof(BeforeDisable)}"); return base.BeforeDisable(); } public void ConfigureServices(IServiceCollection services) { } public void Configure(IApplicationBuilder app) { var webSocketOptions = new WebSocketOptions() { // KeepAliveInterval - 向客户端发送 "ping" 帧的频率,以确保代理保持连接处于打开状态。 默认值为 2 分钟。 KeepAliveInterval = TimeSpan.FromSeconds(120), }; app.UseWebSockets(webSocketOptions); } public int ConfigureOrder { get { return 2; } } public int ConfigureServicesOrder { get { return 2; } } } }
当执行 _components[c](app) 报 System.NullReferenceException: 'Object reference not set to an instance of an object.'
_components[c](app)
System.NullReferenceException: 'Object reference not set to an instance of an object.'
_components[0] 不为 null, 是内部,当 _components[0]() 执行 Func<RequestDelegate, RequestDelegate> 委托时,才报错
_components[0]
_components[0]()
Func<RequestDelegate, RequestDelegate>
猜测,ApplicationBuilder 还是需要 IServiceProvider ,可能需要什么 Service,
ApplicationBuilder
IServiceProvider
但奇怪的是,之前做过的实验, IPluginFinder 却可以正常从 Middleware 的 InvokeAsync 方法上,通过依赖注入获取
IPluginFinder
Middleware
InvokeAsync
当执行
_components[c](app)
报System.NullReferenceException: 'Object reference not set to an instance of an object.'
_components[0]
不为 null, 是内部,当_components[0]()
执行Func<RequestDelegate, RequestDelegate>
委托时,才报错