ASP.NET没有合适的WebSocketManagerMiddleware构造函数

时间:2017-03-24 04:35:19

标签: c# asp.net asp.net-core dnx dnx50

创建像这样的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构造函数是否有错误,但我不知道。 有人知道吗?

感谢。

1 个答案:

答案 0 :(得分:4)

从错误中我猜测WebSocketHandler未添加到启动类中的IServicesCollection。将它添加到服务集合后,应该能够按预期注入它。通常,这是在使用默认模板创建的ASP.NET Core应用程序的ConfigureServices方法中完成的。