Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Make hosting configuration consistent #469

Merged
merged 1 commit into from
Nov 10, 2015
Merged

Make hosting configuration consistent #469

merged 1 commit into from
Nov 10, 2015

Conversation

pakrym
Copy link
Contributor

@pakrym pakrym commented Nov 9, 2015

@dnfclas
Copy link

dnfclas commented Nov 9, 2015

Hi @pakrym, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;


namespace Microsoft.AspNet.Hosting
{
public class WebHostConfiguration
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps consider making this a POCO and just using ConfigurationBinder to directly bind against config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HaoK can it handle two keys for one property and 1/0 boolean property value?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this isn't a pattern we use anywhere else.

Copy link
Member

Choose a reason for hiding this comment

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

You could just have a string property that maps to the key in config, and then expose the current logic just like you do now.

public string DetailedErrors { get; set; }

public bool IsDetailed { get { <same logic as you have> }

@pakrym
Copy link
Contributor Author

pakrym commented Nov 9, 2015

🆙 📅

private const string ServerKey = "server";
private const string WebRootKey = "webroot";

public WebHostOptions(string application, bool detailedErrors, string environment, string server, string webRoot)
Copy link
Member

Choose a reason for hiding this comment

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

no params needed

@pakrym
Copy link
Contributor Author

pakrym commented Nov 9, 2015

🆙 📅

private const string ApplicationKey = "app";
private const string DetailedErrorsKey = "detailederrors";
private const string EnvironmentKey = "environment";
private const string OldEnvironmentKey = "ENV";
Copy link
Member

Choose a reason for hiding this comment

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

nit:can you move this to the bottom

@davidfowl
Copy link
Member

Nuke those tests that change the env and :shipit:

|| string.Equals("1", configuration[DetailedErrorsKey], StringComparison.OrdinalIgnoreCase);
Environment = configuration[EnvironmentKey] ?? configuration[OldEnvironmentKey];
Server = configuration[ServerKey];
WebRoot = configuration[WebRootKey];
Copy link
Member

Choose a reason for hiding this comment

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

So if you wanted to use the config binder, it would look something more like this, the only weirdness is with the Environment/DetailedErrors properties which need a method to add the logic.

public class WebHostOptions {
    public string App { get; set; }
    public string Server {get; set; }
   public string WebRoot {get; set; }
   public string DetailedErrors {get; set; }
   public string Environment {get; set; }
   public string Env {get; set; }

   public bool ShowDetailedErrors { get {
      return string.Equals("true", DetailedErrors)
                || string.Equals("1", DetailedErrors) ;
   } }

   public string ResolveEnvironment() {
      return Environment ?? Env;
   }
}

To get it out of config assuming its at the root level:
   config.Get<WebHostOptions>();

Copy link
Member

Choose a reason for hiding this comment

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

The upside, is you can nuke the keys (the property names for the POCO are automatically the keys. It would just work except for the weirdness around DetailedErrors and supporting the old Env key...

@pakrym pakrym merged commit 660f1ca into dev Nov 10, 2015
@davidfowl
Copy link
Member

@pakrym make an announcement

@pakrym pakrym deleted the pakrym/config branch January 8, 2016 18:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants