In this post, we will see how to resolve Is there a way to create route groups in an aspnet controller?
Question:I want to know if there’s a way to create subclasses that act as a routing group for an api using AspNetCore Mvc.
These are the routes I need to use.
myServicedoesn’t work in the subclasses. I used that code as I felt it explained best what I want to accomplish. (I had the subclasses inherit
ApiControllerso that I could use
myServiceinside those methods but that didn’t fix the routes not working.)
The reason I’m on stack overflow is because I can’t get this to work, and I can’t find anything online.
I’m using Swagger to test the routes, that’s how I can see that they’re not showing up.
All help is greatly appreciated.
Best Answer:These would be separate controllers. There’s a good argument for doing it this way (idiomatically), anyone with experience would instantly recognise the pattern and know exactly how things work.
You would use a base controller to capture the service dependency:
If you have better answer, please add a comment about this, thank you!