简体   繁体   English

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

[英]ASP.NET No suitable constructor for WebSocketManagerMiddleware

I got error when created WebSocketManagerExtensions like this: 创建这样的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 method: MapWebSocketManager方法:

public static IApplicationBuilder MapWebSocketManager(this IApplicationBuilder app,
                                                            PathString path,
                                                            WebSocketHandler handler)
{
    return app.Map(path, (_app) => _app.UseMiddleware<WebSocketManagerMiddleware>(handler));
}

WebSocketManagerMiddleware constructor: WebSocketManagerMiddleware构造函数:

public WebSocketManagerMiddleware(RequestDelegate next,
                                      WebSocketHandler webSocketHandler)
{
    _next = next;
    _webSocketHandler = webSocketHandler;
}

I know if there is something error with my WebSocketManagerMiddleware constructor, but I have no idea. 我知道WebSocketManagerMiddleware构造函数是否存在错误,但我不知道。 Anyone know? 有人知道吗

Thanks. 谢谢。

From the error I would guess WebSocketHandler was not added to the IServicesCollection in your startup class. 从错误中,我猜想WebSocketHandler没有添加到启动类的IServicesCollection中。 Once you add it to the services collection, it should be able to be injected as expected. 将其添加到服务集合后,应该可以按预期进行注入。 Typically this is done in the ConfigureServices method for an ASP.NET Core application created from the default templates. 通常,这是通过默认模板创建的ASP.NET Core应用程序的ConfigureServices方法中完成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM