Jus*_*wan 2 c# asp.net dnx dnx50 asp.net-core
创建 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.
Run Code Online (Sandbox Code Playgroud)
MapWebSocketManager 方法:
public static IApplicationBuilder MapWebSocketManager(this IApplicationBuilder app,
PathString path,
WebSocketHandler handler)
{
return app.Map(path, (_app) => _app.UseMiddleware<WebSocketManagerMiddleware>(handler));
}
Run Code Online (Sandbox Code Playgroud)
WebSocketManagerMiddleware 构造函数:
public WebSocketManagerMiddleware(RequestDelegate next,
WebSocketHandler webSocketHandler)
{
_next = next;
_webSocketHandler = webSocketHandler;
}
Run Code Online (Sandbox Code Playgroud)
我知道我的WebSocketManagerMiddleware构造函数是否有问题,但我不知道。有人知道吗?
谢谢。
从我猜测的错误WebSocketHandler中没有添加到IServicesCollection您的启动类中。将它添加到服务集合后,它应该能够按预期注入。通常,这是在ConfigureServices从默认模板创建的 ASP.NET Core 应用程序的方法中完成的。
| 归档时间: |
|
| 查看次数: |
4186 次 |
| 最近记录: |