Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only invoke 'IsService' check once in resolution #47097

Merged
merged 4 commits into from
Mar 17, 2023

Conversation

captainsafia
Copy link
Member

@captainsafia captainsafia commented Mar 8, 2023

Follow-up to #47079 (comment).

Closes #47224.

{
foreach (var parameter in endpoint.Parameters)
{
if (parameter.Source == EndpointParameterSource.JsonBodyOrService)
{
codeWriter.WriteLine("var serviceProviderIsService = options?.ServiceProvider?.GetService<IServiceProviderIsService>();");
codeWriter.Write($@"var {parameter.Name}_JsonBodyOrServiceResolver = ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This includes the parameter name in the variable name. What is the parameter name here? Is it the C# method parameter name or the route parameter name? Need to be careful about using the route name because it could contain invalid C# name characters.

Copy link
Member

@JamesNK JamesNK Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this, and I believe the parameter name here can be overridden by something like [FromRoute(Name = "1")]. The generated source wouldn't compile because a variable can't start with a number.

Consider using the parameter index instead, e.g. param1_JsonBodyOrServiceResolver

Edit: Issue #47129. Don't need to fix it in this PR, but afterward, someone should test if it's a problem or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be based on the parameter name even if it can be overridden. That should just change the lookup key, not the variable name.

Copy link
Member

@adityamandaleeka adityamandaleeka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but I'd like someone who's spent more time in this space to also review.

Copy link
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Safia and I looked at this together yesterday when looking at dealing with some issues related to array handling.

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but we should probably track @JamesNK's comment about using IParameterSymbol.Name rather than EndpointParameter.Name to derive local variable names in an issue.

Edit: I missed that #47129 was already filed for this.

@captainsafia captainsafia merged commit 2a7dc90 into main Mar 17, 2023
@captainsafia captainsafia deleted the saifa/body-v-service-followup branch March 17, 2023 01:18
@ghost ghost added this to the 8.0-preview3 milestone Mar 17, 2023
@mitchdenny
Copy link
Member

LGTM, but we should probably track @JamesNK's comment about using IParameterSymbol.Name rather than EndpointParameter.Name to derive local variable names in an issue.

Edit: I missed that #47129 was already filed for this.

.... and fixed with #47272

@ghost
Copy link

ghost commented Mar 17, 2023

Hi @mitchdenny. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only invoke 'IsService' check once in resolution
8 participants