Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify the application base path in ConfigurationBuilder in beta8

I used to specify the application base path for the ConfigurationBuilder like this:

public Startup(IApplicationEnvironment appEnv)
{
    var configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
        .AddJsonFile("config.json")
        .AddEnvironmentVariables();

    Configuration = configurationBuilder.Build();
}

However, as of beta8, the constructor of ConfigurationBuilder does not take an application base path argument anymore and it throws an exception now.

How can I specify the base path?

like image 805
Henk Mollema Avatar asked Oct 16 '15 11:10

Henk Mollema


1 Answers

If we look at the source code of ConfigurationBuilder, we can see that the constructor no longer accepts a string representing the application base path. In stead, we have to use the SetBasePath() extension method on the IConfigurationBuilder interface to specify it:

public Startup(IApplicationEnvironment appEnv)
{
    var configurationBuilder = new ConfigurationBuilder()
        .SetBasePath(appEnv.ApplicationBasePath)
        .AddJsonFile("config.json")
        .AddEnvironmentVariables();

    Configuration = configurationBuilder.Build();
}

The particular commit can be found here.

like image 197
Henk Mollema Avatar answered Sep 28 '22 02:09

Henk Mollema