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

EndpointBuilder.ApplicationServices should use init instead of set #43544

Closed
halter73 opened this issue Aug 25, 2022 · 2 comments · Fixed by #43543
Closed

EndpointBuilder.ApplicationServices should use init instead of set #43544

halter73 opened this issue Aug 25, 2022 · 2 comments · Fixed by #43543
Labels
api-approved API was approved in API review, it can be implemented area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone

Comments

@halter73
Copy link
Member

halter73 commented Aug 25, 2022

Background and Motivation

When doing more work with EndpointBuilder as part of #43543, I noticed that it was odd and unnecessary that ApplicationServices could be modified after construction. Using init doesn't completely prevent this, but it makes it clear it's unintended.

I also think that IEndpointMetadataProvider and IEndpointMetadataProvider belong in Http.Abstractions instead of Http.Extensions. It doesn't have any big dependency, and we already have all our other endpoint metadata related stuff there like EndpointBuilder itself.

Proposed API

namespace Microsoft.AspNetCore.Builder;
 
public abstract class EndpointBuilder
{
-    public IServiceProvider ApplicationServices { get; set; } = EmptyServiceProvider.Instance;
+    public IServiceProvider ApplicationServices { get; init; } = EmptyServiceProvider.Instance;
}
- Microsoft.AspNetCore.Http.Extensions.dll
+ Microsoft.AspNetCore.Http.Abstractions.dll

namespace Microsoft.AspNetCore.Builder;

public interface IEndpointMetadataProvider
{
     static abstract void PopulateMetadata(MethodInfo method, EndpointBuilder builder);
}

public interface IEndpointParameterMetadataProvider
{
     static abstract void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder);
}

Usage Examples

var builder = new RouteEndpointBuilder(requestDelegate, updatedRoutePattern, route.Order)
{
    DisplayName = action.DisplayName,
    ApplicationServices = _serviceProvider,
};

Alternative Designs

Leave it as set. Leave the providers in Http.Extensions.dll.

Risks

I think it's riskier to leave it as set. It's new API, and we could always remove the init-onlyness in a later release. I don't think it's a huge problem either way though.

If someone wanted to enlighten an existing EndpointBuilder they didn't construct, the C# language will now try to stop them from modifying it. This might be annoying, but changing this value after construction could lead to some weird hard-to-diagnose bugs.

I cannot think of any justification for not moving the providers to Http.Abstractions.dll.

@halter73 halter73 added api-suggestion Early API idea and discussion, it is NOT ready for implementation api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Aug 25, 2022
@halter73 halter73 added this to the 7.0-rc2 milestone Aug 25, 2022
@ghost
Copy link

ghost commented Aug 25, 2022

Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:

  • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
  • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
  • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.

@BrennanConroy BrennanConroy added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Aug 25, 2022
@halter73
Copy link
Member Author

halter73 commented Sep 2, 2022

This was approved over email.

@BrennanConroy points out "The set vs init part was likely an oversight during the API review. I don’t see any references in the PR/issue about why it was made settable, and no one is using the setter today." And that "the dll move also makes sense, those were the only interfaces in that assembly, which is probably a sign that this is a good move.

@halter73 halter73 added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels Sep 2, 2022
@halter73 halter73 closed this as completed Sep 2, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Oct 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants