Skip to content

Add the ConfigurationManager to the IServiceCollection #36832

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

Merged
merged 1 commit into from
Sep 22, 2021

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Sep 22, 2021

Fixes #36829

Description

Add an IConfiguration to the service collection for scenarios where uses end up prematurely building the service provider or sniffing the IServiceCollection for it. We then remove the ConfigurationManager reference it from the final IServiceCollection to avoid cycles in the configuration graph that result in stack overflows (we link the configuration manager to the final configuration that has been built).

Customer Impact

This can affect libraries that try to access the service provider before the bootstrapping of the application is complete. This should be identical between .NET 5 and .NET 6 but missing the IConfiguration at this early stage has broken a customer's library.

Regression

Yes

Testing

Added unit tests and verified customer scenario.

Risk

Low

- Add an IConfiguration to the service collection for scenarios where uses end up prematurely building the service provider or sniffing the IServiceCollection for it. We then remove the ConfigurationManager reference it from the final IServiceCollection to avoid cycles in the configuration graph that result in stack overflows (we link the configuration manager to the final configuration that has been built).
- Added tests
var app = builder.Build();

// These are different
Assert.NotSame(app.Configuration, builder.Configuration);
Copy link
Member

Choose a reason for hiding this comment

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

This is kinda annoying, no? Can we keep the builder.Configuration registration if it's added manually?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can make WebApplication.Configuration and WebApplicationBuilder.Configuration match, but I can't make them match the final IConfiguration instance. The problem is that we need to chain the ConfigurationManager to the final IConfiguration so we can see the providers added by unit tests. There's no way to get the IConfiguration from the built application other than via the IServiceProvider.

@davidfowl
Copy link
Member Author

cc @dotnet/aspnet-build This was approved. Also cc @Pilchie

@davidfowl davidfowl added the Servicing-approved Shiproom has approved the issue label Sep 22, 2021
@dougbu
Copy link
Member

dougbu commented Sep 22, 2021

Just curious: Is this a backport from 'main'❔ Our current approach is supposedly to start all fixes in 'main'

@dougbu dougbu merged commit ce73350 into release/6.0-rc2 Sep 22, 2021
@dougbu dougbu deleted the davidfowl/host-missing-config branch September 22, 2021 22:17
@dougbu
Copy link
Member

dougbu commented Sep 22, 2021

Should also mention this fix will not reach 'main' unless you do or have done something manual

@davidfowl
Copy link
Member Author

/backport to main

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@davidfowl an error occurred while backporting to main, please check the run log for details!

Error: @davidfowl is not a repo collaborator, backporting is not allowed.

@Pilchie
Copy link
Member

Pilchie commented Sep 22, 2021

I don't think you can run backport from a branch you don't have permission to merge from.

@davidfowl
Copy link
Member Author

😮

@dougbu
Copy link
Member

dougbu commented Sep 22, 2021

The failures to backport is a GitHub bug affecting many members of our team with push rights. Very annoying and @TanayParikh doesn't seem to be getting traction from GitHub: They basically said we should switch to giving individual people rights, undermining the entire value of GitHub teams☹️

@dougbu
Copy link
Member

dougbu commented Sep 22, 2021

/backport to main

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@dougbu an error occurred while backporting to main, please check the run log for details!

Error: @dougbu is not a repo collaborator, backporting is not allowed.

@dougbu
Copy link
Member

dougbu commented Sep 22, 2021

Wow, I can merge to this branch as well as the target branch and have admin rights (through a team). Wonder how @SteveSandersonMS was able to backport from 'main' to 'release/6.0' in #36839

/cc @TanayParikh -- more fodder for your ticket


@MattGal do you have a direct GitHub contact. Our "backport bot" isn't working much right now even though we haven't changed it in months. See https://github.com/dotnet/aspnetcore/blob/main/.github/workflows/backport.yml

@ViktorHofer @Anipik @ericstj @jeffhandley is the runtime team also seeing issues w/ your very similar backport GitHub action❔ (@akoeplinger is on vacation)

@TanayParikh
Copy link
Contributor

/cc @TanayParikh -- more fodder for your ticket

Thanks, added the note and requested escalation on the support ticket.

@MattGal
Copy link
Member

MattGal commented Sep 22, 2021

@MattGal do you have a direct GitHub contact. Our "backport bot" isn't working much right now even though we haven't changed it in months. See https://github.com/dotnet/aspnetcore/blob/main/.github/workflows/backport.yml

Sadly not, the folks I talk with mostly are technically ADO, though that's "GitHub". I'd ask @mmitche / @chcosta maybe?

@dotnet dotnet deleted a comment Sep 22, 2021
davidfowl added a commit that referenced this pull request Sep 22, 2021
- Add an IConfiguration to the service collection for scenarios where uses end up prematurely building the service provider or sniffing the IServiceCollection for it. We then remove the ConfigurationManager reference it from the final IServiceCollection to avoid cycles in the configuration graph that result in stack overflows (we link the configuration manager to the final configuration that has been built).
- Added tests
davidfowl added a commit that referenced this pull request Sep 23, 2021
- Add an IConfiguration to the service collection for scenarios where uses end up prematurely building the service provider or sniffing the IServiceCollection for it. We then remove the ConfigurationManager reference it from the final IServiceCollection to avoid cycles in the configuration graph that result in stack overflows (we link the configuration manager to the final configuration that has been built).
- Added tests
@akoeplinger
Copy link
Member

I'm back from vacation 😄

It looks like this was caused by a change on GitHub's end, according to this thread it was reverted so we shouldn't be hitting this issue anymore: https://github.community/t/github-api-collaborators-access-changed-today/201259/14

@akoeplinger
Copy link
Member

akoeplinger commented Nov 5, 2021

@dougbu @davidfowl @TanayParikh @MattGal so I just figured out the root cause of this issue: the auth token used by the GitHub Actions backport job apparently can't see you're a contributor if your membership visibility in the dotnet GitHub org is set to Private - it needs to be set to Public.

You can go to https://github.com/orgs/dotnet/people, search for your username and select Public in the dropdown:

image

You can confirm it worked by going to your https://github.com/username profile in an incognito window and see if the purple .NET org logo shows up there (if you look at a user while signed in to your account it will show the org membership regardless of the setting).

@dotnet dotnet deleted a comment Nov 5, 2021
@dotnet dotnet deleted a comment Nov 5, 2021
@MattGal
Copy link
Member

MattGal commented Nov 5, 2021

@akoeplinger makes sense, the dependency flow failure tagging model has the same problem because the permissions to know the membership when it's private are nigh on org-admin permissions and we avoid our bots having that.

@ghost
Copy link

ghost commented Nov 5, 2021

Hi @MattGal. 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.

@dougbu
Copy link
Member

dougbu commented Nov 5, 2021

Is there any downside to making our memberships public❔ I like the new look of my profile (
image
) but, noticed most .NET members are private.

@TanayParikh
Copy link
Contributor

/backport to main

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2021

@TanayParikh
Copy link
Contributor

Just validating, will immediately delete the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2021

@TanayParikh backporting to main failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Add the ConfigurationManager to the IServiceCollection - Add an IConfiguration to the service collection for scenarios where uses end up prematurely building the service provider or sniffing the IServiceCollection for it. We then remove the ConfigurationManager reference it from the final IServiceCollection to avoid cycles in the configuration graph that result in stack overflows (we link the configuration manager to the final configuration that has been built). - Added tests
Using index info to reconstruct a base tree...
M	src/DefaultBuilder/src/WebApplicationBuilder.cs
M	src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebApplicationTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebApplicationTests.cs
CONFLICT (content): Merge conflict in src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebApplicationTests.cs
Auto-merging src/DefaultBuilder/src/WebApplicationBuilder.cs
CONFLICT (content): Merge conflict in src/DefaultBuilder/src/WebApplicationBuilder.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Add the ConfigurationManager to the IServiceCollection - Add an IConfiguration to the service collection for scenarios where uses end up prematurely building the service provider or sniffing the IServiceCollection for it. We then remove the ConfigurationManager reference it from the final IServiceCollection to avoid cycles in the configuration graph that result in stack overflows (we link the configuration manager to the final configuration that has been built). - Added tests
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@TanayParikh
Copy link
Contributor

TanayParikh commented Nov 5, 2021

Okay great, I think that did it! Thanks @akoeplinger!

@MattGal
Copy link
Member

MattGal commented Nov 5, 2021

Is there any downside to making our memberships public❔ I like the new look of my profile ( image ) but, noticed most .NET members are private.

That's just the default. I suppose it may make you potentially the target of advertising / recruiting / worse things, beyond that I don't think there's a downside.

@ghost
Copy link

ghost commented Nov 5, 2021

Hi @MattGal. 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-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-hosting Servicing-approved Shiproom has approved the issue
Projects
None yet
8 participants