Method LoadEnv
| Improve this Doc View SourceLoadEnv()
Loads an .env file based on the environment (development, test, staging or production). This method will load these .env files in the following order:
.env.[environment].local
(has the highest priority)..env.local
.env.[environment]
.env
(has the lowest priority).
environment
is specified by the actual environment variable DOTNET_ENV
.
It should be noted that the default environment will be development
or dev
if the environment is never specified with DOTNET_ENV
.
Declaration
public IEnvironmentVariablesProvider LoadEnv()
Returns
Type | Description |
---|---|
IEnvironmentVariablesProvider | An instance representing the provider of environment variables. |
Implements
Remarks
This method starts find the .env file in the current directory and if it does not found it, it starts find in the parent directories of the current directory.
Exceptions
Type | Condition |
---|---|
ParserException | If the parser encounters one or more errors. This exception is not thrown if the IgnoreParserException() method is invoked. |
FileNotFoundException | If the .env files are not found. This exception is only thrown if the EnableFileNotFoundException() method is invoked. |
LoadEnv(out EnvValidationResult)
Loads an .env file based on the environment (development, test, staging or production). This method will load these .env files in the following order:
.env.[environment].local
(has the highest priority)..env.local
.env.[environment]
.env
(has the lowest priority).
environment
is specified by the actual environment variable DOTNET_ENV
.
It should be noted that the default environment will be development
or dev
if the environment is never specified with DOTNET_ENV
.
Declaration
public IEnvironmentVariablesProvider LoadEnv(out EnvValidationResult result)
Parameters
Type | Name | Description |
---|---|---|
EnvValidationResult | result | The result contains the errors found by the loader. |
Returns
Type | Description |
---|---|
IEnvironmentVariablesProvider | An instance representing the provider of environment variables. |
Implements
Remarks
This method starts find the .env file in the current directory and if it does not found it, it starts find in the parent directories of the current directory.
Exceptions
Type | Condition |
---|---|
ParserException | If the parser encounters one or more errors. This exception is not thrown if the IgnoreParserException() method is invoked. |
FileNotFoundException | If the .env files are not found. This exception is only thrown if the EnableFileNotFoundException() method is invoked. |