Parameter Binder error: implement TryParse
Hello.
Even if I'm already implementing BindAsync in my custom Binder, I get an error saying I need to implement TryParse. If I remove the parameter from the route, then it simply will ignore it:
21 Replies
I assume I should just use TryParse and not lose anything? But I'm still curious about why I'm getting the error.
Actually I can't use TryParse otherwise I can't get access to services
won't something like
app.MapGet("/works/{decryptedId}", async (context) => ...)
be better?Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Parameter binding in Minimal API applications
Learn how parameters are populated before invoking minimal route handlers.
For route, query, and header binding sources, bind custom types by adding a static TryParse method for the type.
You mean get the HttpContext directly?
Without a binder?
yeah. It's a thing
idek what a binder is
Just to decrypt the id
the id is a long, I receive it as an encrypted string in the route
I thought a binder would do the job
layers! minimal API being minimal comes first
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I know, but TryParse don't have HttpContext
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
So I can't get the Encoder from the Services
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
If I use TryParse, the BindAsync is ignored
I'll go with what @Lyrcaxis suggested
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
alr
Actually, I don't think the context is even necessary
I can just get the encoder directly
Guess I overcomplicated stuff for no reason
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I know, I've been using it
So idk what happened for me to think of binders lol
ohh didn't know that.. good info 👍
although yeah hardly a need for more than
HttpContext
u need more u can set it up with other identifiers or cookiesUnknown User•2w ago
Message Not Public
Sign In & Join Server To View