简体   繁体   中英

ASP.NET No suitable constructor for WebSocketManagerMiddleware

I got error when created WebSocketManagerExtensions like this:

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:

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

WebSocketManagerMiddleware constructor:

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. Anyone know?

Thanks.

From the error I would guess WebSocketHandler was not added to the IServicesCollection in your startup class. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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