Replies: 1 comment 1 reply
-
I'm not sure if this is similar to what you are trying to accomplish but I saw your discussion and thought I'd share: #60194 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
I've been experimenting with Minimal APIs to find a clean way to organize my endpoints, and I finally came across something I am quite happy with. I'd like to get your opinion on it.
The idea is to use
[AsParameters]
to inject a handler object that will hold everything needed to process the request (parameters, services, etc.), as well as aHandle()
method that will be used as the handler delegate. Of course, the class could also contain private methods if the logic is more complexe.A simple example looks like this
Note: I included some validation and cancellation support to illustrate what can be done.
With the mapping code
Is this a recommended pattern? Does using
[AsParameters]
for handler injection align with best practices for .NET Minimal APIs?Are there alternative patterns or approaches you would recommend for achieving similar goals in a more efficient or standardized way?
Thanks a lot for your answers 😄
Beta Was this translation helpful? Give feedback.
All reactions