Skip to content

Apply hosting environment via command line args #34794

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 3 commits into from
Jul 28, 2021

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Jul 28, 2021

  • This makes sure that the entire application can see changes to host configuration (env, content root etc).
  • Added tests to verify those scenarios
  • One caveat is that the application can still override the test values manually (fore.g not passing the args)

Fixes #33889

- This makes sure that the entire applicaton can see changes to host configuration (env, content root etc).
- Added tests to verify those scenarios
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jul 28, 2021
@davidfowl davidfowl requested a review from halter73 July 28, 2021 09:22
@davidfowl davidfowl added old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-minimal-hosting and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Jul 28, 2021
{
var config = new[]
{
KeyValuePair.Create("Greeting", "Bonjour tout le monde"),
Copy link
Member

Choose a reason for hiding this comment

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

You kept it 😄

Copy link
Contributor

@pranavkm pranavkm left a comment

Choose a reason for hiding this comment

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

I'm not familiar enough with this area to sign off. @halter73 could you look at this?

Comment on lines 1 to 2
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Copy link
Contributor

Choose a reason for hiding this comment

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

Undo

// Transform the host configuration into command line arguments
foreach (var (key, value) in _hostConfiguration.AsEnumerable())
{
args.Add($"--{key}={value}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to do any fancy escaping for value? Like can values have spaces which would break config parsing? I'm not super familiar with this area

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 don't see how it breaks given how the parsing works. We're not parsing the command line string, we're parsing each arg.

I also don't see a way to escape - or / so that might be the only problem.

Copy link
Member

Choose a reason for hiding this comment

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

An = in the key would also mess this up, right? I'm not sure how realistic that is.

Copy link
Member

Choose a reason for hiding this comment

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

I also don't see a way to escape - or / so that might be the only problem.

You could always base64 encode/decode. Stripping and adding back the = padding characters might be a pain though.

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 think we wait until somebody hits this then we fix it by supporting escape sequences in the command line configuration provider, the problem is general.

@davidfowl davidfowl merged commit 4a1ced1 into main Jul 28, 2021
@davidfowl davidfowl deleted the davidfowl/waf-apply-hosting-env branch July 28, 2021 21:58
@ghost ghost added this to the 6.0-rc1 milestone Jul 28, 2021
@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label 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 old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebApplicationFactory<T> does not default to Development environment with minimal hosting
5 participants