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

First class Configuration and Logging in WebHostBuilder #955

Closed
glennc opened this issue Mar 2, 2017 · 7 comments
Closed

First class Configuration and Logging in WebHostBuilder #955

glennc opened this issue Mar 2, 2017 · 7 comments

Comments

@glennc
Copy link
Member

glennc commented Mar 2, 2017

We want to enable the following program main:

public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseConfiguration((configBuilder, env) => 
                {
                    configBuilder.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                                 .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                                 .AddEnvironmentVariables()
                                 .AddCommandLine(args);
                })
                .UseLogging((factory, config) =>
                {
                    factory.AddFilter(config.GetSection("Logging"));
                    factory.AddConsole();
                    factory.AddDebug();
                })
                .UseIISIntegration()
                .UseStartup<Startup>()
                .UseKestrel()
                .Build();

            host.Run();
        }

This issue is to track the WebHostBuilder part of this.

@glennc glennc added this to the 2.0.0 milestone Mar 2, 2017
@glennc glennc self-assigned this Mar 2, 2017
@Tratcher
Copy link
Member

Tratcher commented Mar 2, 2017

  • With an eye to removing these parts from Startup and exposing config via DI.

@cwe1ss
Copy link
Contributor

cwe1ss commented Mar 2, 2017

Sounds great! How will users be able to get the configuration object?

@cwe1ss
Copy link
Contributor

cwe1ss commented Mar 2, 2017

With an eye to removing these parts from Startup and exposing config via DI.

Would I be able to resolve IConfiguration or would it be a separate type? My concern with IConfiguration are scenarios where applications use multiple independent configuration objects. (e.g. one for appSettings and one for secrets from Azure Key Vault). It might not be clear what gets injected when people use IConfiguration. Not sure if this is a real concern though?!

@glennc
Copy link
Member Author

glennc commented Mar 2, 2017

At the moment I think we will just put IConfigurationRoot in DI. We are hearing from many people that it's what they want.

Not completely obvious in this, but relevent to you @cwe1ss is that this will play into the other issue about deprecating AddProvider on LoggerFactory and allowing Serilog, NLog, etc to replace the LoggerFactory instead of having a provider.

@glennc
Copy link
Member Author

glennc commented Mar 2, 2017

Having IConfiguration in DI doesn't stop you from using multiple, but you would need to define them yourselves and pick which one is the one that goes into DI. Ideally use Options as well instead of Configuration directly.

@cwe1ss
Copy link
Contributor

cwe1ss commented Mar 2, 2017

Yep, just wanted to point it out... it might not be an issue.
Will you add IConfigurationRoot and IConfiguration? IConfiguration seems nicer to me for DI because it's the more generic interface. People who use 3rd party DI containers could probably do more stuff with it (e.g. Injecting just a section).

Not completely obvious in this, but relevent to you @cwe1ss is that this will play into the other issue about deprecating AddProvider on LoggerFactory and allowing Serilog, NLog, etc to replace the LoggerFactory instead of having a provider.

Awesome!!

@cwe1ss
Copy link
Contributor

cwe1ss commented Mar 2, 2017

PS: I'm using Options most of the time, yes. So again, not sure how important the IConfiguration scenario really is.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants