Replies: 1 comment
-
I ended up using the
And register it as a service in the app startup:
And, if anyone is interested, here is how I am adding Routes and HttpMethods to the Actions (it seems to work...):
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to have controllers with default Route URLs and HTTP Method generated by custom code and not require any
HttpPost|Get|etc
attributes (route actions will default toPost
). I can do this usingMicrosoft.AspNetCore.Mvc.ApplicationModels.IActionModelConvention
. However I cannot then use[ApiController]
on the controller since there is no explicit attribute routing - I get the error:"<Controller Action> does not have an attribute route. Action methods on controllers annotated with ApiControllerAttribute must be attribute routed"
Is there a way to dynamically add default routes and http methods to controller actions AND use the [ApiController] attribute?
Related Questions
[ApiController]
- ie not having to set[FromBody]
for params, etcCore Requirement
I'd like to create an OpenAPI backend and for use on an JS SPA client code gen on the front end. Since the API is only consumed by the SPA, and the client api will be auto code gen - I don't really care about hardcoded routes, or even using "correct" HTTP methods (everything could just be a POST). So I'd like to get rid of all that boilerplate in my controllers.
Current Thoughts/Ideas
The
I*Convention
s aren't applied until afterMicrosoft.AspNetCore.Mvc.ApplicationModels.ApiBehaviorApplicationModelProvider.EnsureActionIsAttributeRouted
validation is executed. So even though I apply aAttributeRouteModel
in the convention, it isn't included in the validationMy next idea is to implement some sort of
Microsoft.AspNetCore.Mvc.ApplicationModels.IApplicationModelProvider
(which is how the[ApiController]
seems to be validated - see:Microsoft.AspNetCore.Mvc.ApplicationModels.ApiBehaviorApplicationModelProvider
) - and try to make sure it's registered and executed before theApiBehaviorApplicationModelProvider
?If that doesn't work then it seems the option would be to get even deeper into something like
Microsoft.AspNetCore.Mvc.Abstractions.IActionDescriptorProvider
- but that seems pretty scary.(Cross Posted on SO: https://stackoverflow.com/q/77588408/79113)
Beta Was this translation helpful? Give feedback.
All reactions