Zygimantas
Zygimantas

Reputation: 8757

Is it possible to use the same router in multiple middlewares?

In Startup.cs I want to configure 2 middlewares:

  1. An app.Use (or app.Map with app.Use) which handles websocket requests, but requires a specific dynamic route endpoint.
  2. app.UseMvc() with attribute routing.

How the router can be created and reused in MVC in such situation?

PS. Here is my related question where I am looking at the same problem from a different perspective: Opening a websocket channel inside MVC controller

Upvotes: 3

Views: 498

Answers (1)

neleus
neleus

Reputation: 2280

I had similar issue and after checking the sources I found that the UseMvc method creates its own instance of RouteBuilder and IRouter. This means that you have no control over the route creation while using UseMvc.

So I can suggest creating an alternative to UseMvc that will create two routes mapped to different handlers, one to Mvc and the second to Websocket. Though I haven't tested it yet, hope it helps.

Upvotes: 1

Related Questions