Skip to content
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

Load an .env file based on environment #14

Closed
MrDave1999 opened this issue Jan 5, 2022 · 1 comment · Fixed by #19
Closed

Load an .env file based on environment #14

MrDave1999 opened this issue Jan 5, 2022 · 1 comment · Fixed by #19
Labels
feature New feature or request
Milestone

Comments

@MrDave1999
Copy link
Owner

MrDave1999 commented Jan 5, 2022

Normally you have files like: .env.dev, .env.test and .env.staging, so you should load the .env file based on your environment. This environment can be defined through an environment variable such as DOTNET_ENV.

For example:

export DOTNET_ENV=staging

This feature can be achieved without modifying the library such as:

new EnvLoader()
      .AddEnvFile($".env.{Environment.GetEnvironmentVariable("DOTNET_ENV")}")
      .Load();

In a future version this feature could be added so that it is not necessary to add this line:

.AddEnvFile($".env.{Environment.GetEnvironmentVariable("DOTNET_ENV")}")
@MrDave1999 MrDave1999 added the feature New feature or request label Jan 9, 2022
@MrDave1999
Copy link
Owner Author

MrDave1999 commented Jan 9, 2022

A possible serious proposal:

new EnvLoader().LoadEnv();

LoadEnv method loads .env file based on environment defined with DOTNET_ENV. The loader will search for these .env files in the following order:

  • .env.[environment].local (has the highest priority)
  • .env.local
  • .env.[environment]
  • .env (has the lowest priority)

The 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.

MrDave1999 added a commit that referenced this issue Feb 1, 2022
MrDave1999 added a commit that referenced this issue Feb 2, 2022
MrDave1999 added a commit that referenced this issue Feb 17, 2022
MrDave1999 added a commit that referenced this issue Feb 17, 2022
@MrDave1999 MrDave1999 added this to the 8.0.0 milestone Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant