Skip to content

Add HostApplicationBuilder - #65109

Merged
halter73 merged 9 commits into
mainfrom
halter73/61634
Mar 5, 2022
Merged

halter73 merged 9 commits into
mainfrom
halter73/61634

Conversation

@halter73

@halter73 halter73 commented Feb 9, 2022 •

Copy link
Copy Markdown
Member

Addresses #61634.

@ghost

ghost commented Feb 9, 2022

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost

ghost commented Feb 9, 2022

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-extensions-hosting
See info in area-owners.md if you want to be subscribed.

Issue Details

Addresses #61634.

I'm on vacation starting tomorrow, so I'm going to leave this as a draft. I won't likely be able to make many changes to this PR until after I come back on the 17th, but please feel free to leave initial feedback.

Author: halter73
Assignees: halter73
Labels:

new-api-needs-documentation, area-Extensions-Hosting

Milestone: -

/// <item><description>enables scope validation on the dependency injection container when <see cref="IHostEnvironment.EnvironmentName"/> is 'Development'</description></item>
/// </list>
/// </remarks>
public static HostApplicationBuilder CreateApplicationBuilder() => new HostApplicationBuilder();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How valuable are these methods? It feels wrong to have 2 public APIs that do exactly the same thing.

On the existing factory methods, We ConfigureDefaults over top of a new HostBuilder(). So for those it makes sense, since the ctor creates a blank builder, and the CreateDefaultBuilder creates one with certain things set.

But here, these factory APIs literally just call the ctor. So do we need both?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

During API review, I suggested adding just these static methods for discoverability. I agreed to add the equivalent constructors, but I think those are less important.

Comment thread src/libraries/Microsoft.Extensions.Hosting/src/HostApplicationBuilder.cs Outdated
Comment thread src/libraries/Microsoft.Extensions.Hosting/src/HostBuilder.cs
Comment thread src/libraries/Microsoft.Extensions.Hosting/src/HostBuilder.cs Outdated
Comment thread src/libraries/Microsoft.Extensions.Hosting/src/HostBuilder.cs
@halter73
halter73 marked this pull request as ready for review February 24, 2022 02:26
Comment thread src/libraries/Microsoft.Extensions.Hosting/src/HostApplicationBuilder.cs Outdated
@halter73

halter73 commented Mar 1, 2022

Copy link
Copy Markdown
Member Author

@eerhardt @maryamariyan I think this is ready for another (hopefully final) review round.

Comment thread src/libraries/Microsoft.Extensions.Hosting/tests/TestApp/Program.cs Outdated
Comment thread src/libraries/Microsoft.Extensions.Hosting/src/HostApplicationBuilder.cs Outdated
}
}

internal sealed class CheckedServiceCollection : IServiceCollection

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if this functionality shouldn't be added to ServiceCollection itself. That way people can just use ServiceCollection without having to define this wrapper in as many places as we do.

It is also in maui: https://github.com/dotnet/maui/blob/5913b3262e7f4c99c3a7fdeacac48037b730e72a/src/Core/src/Hosting/Internal/MauiApplicationServiceCollection.cs#L8-L23

See #44728 and #52363 for reasons to use ServiceCollection where possible.

@halter73 halter73 Mar 2, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I like this idea. It would require adding new public API to ServiceCollection to trigger making it readonly. What do you think about a new instance method called MakeReadOnly()? I don't like adding an IsReadonly setter to the public API because that would allow transitioning back to not being readonly. If this makes sense, I can file a new API proposal. I don't think it should block this PR though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you think about an instance method call MakeReadOnly()?

I like that.

If this makes sense I can file a new API proposal.

Yes, please. If you have time.

I don't think it should block this PR though.

Agreed.

Comment thread src/libraries/Microsoft.Extensions.Hosting/src/HostApplicationBuilder.cs Outdated
Comment thread src/libraries/Microsoft.Extensions.Hosting/src/HostApplicationBuilder.cs Outdated
@halter73

halter73 commented Mar 3, 2022

Copy link
Copy Markdown
Member Author

I addressed the new feedback and opened an issue for ServiceCollection.MakeReadOnly() at #66126.

@eerhardt eerhardt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks for the great work here @halter73.

@maryamariyan - any thoughts?

Comment thread src/libraries/Microsoft.Extensions.Hosting/src/HostApplicationBuilder.cs Outdated
Comment thread src/libraries/Microsoft.Extensions.Hosting/src/HostApplicationBuilder.cs Outdated
@halter73
halter73 merged commit 1b3ef86 into main Mar 5, 2022
@halter73
halter73 deleted the halter73/61634 branch March 5, 2022 01:15
@ghost ghost locked as resolved and limited conversation to collaborators Apr 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants