创建这样的WebSocketManagerExtensions时出现错误:
System.InvalidOperationException
A suitable constructor for type
'CustomerManagementCore.WebSocketManager.WebSocketManagerMiddleware' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
MapWebSocketManager
方法:public static IApplicationBuilder MapWebSocketManager(this IApplicationBuilder app,
PathString path,
WebSocketHandler handler)
{
return app.Map(path, (_app) => _app.UseMiddleware<WebSocketManagerMiddleware>(handler));
}
WebSocketManagerMiddleware
构造函数:public WebSocketManagerMiddleware(RequestDelegate next,
WebSocketHandler webSocketHandler)
{
_next = next;
_webSocketHandler = webSocketHandler;
}
我知道我的
WebSocketManagerMiddleware
构造函数是否存在错误,但我不知道。有人知道吗
谢谢。
最佳答案
从错误中我想WebSocketHandler
没有添加到启动类的IServicesCollection
中。将其添加到服务集合后,应该可以按预期进行注入。通常,这是通过默认模板创建的ASP.NET Core应用程序的ConfigureServices
方法完成的。