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

Add a configuration method to set the environment variables provider #51

Closed
MrDave1999 opened this issue Mar 7, 2022 · 0 comments · Fixed by #53
Closed

Add a configuration method to set the environment variables provider #51

MrDave1999 opened this issue Mar 7, 2022 · 0 comments · Fixed by #53
Labels
feature New feature or request
Milestone

Comments

@MrDave1999
Copy link
Owner

MrDave1999 commented Mar 7, 2022

The idea of this new function is that the consumer can create his own environment variables provider and inject it into a configuration method.

For example:

class CustomProvider : IEnvironmentVariablesProvider
{
     private Dictionary<string, string> _keyValuePairs = new Dictionary<string, string>();

     public string this[string variable] 
     {
          get => _keyValuePairs.ContainsKey(variable) ? _keyValuePairs[variable] : null;
          set => _keyValuePairs[variable] = value;
     }

     public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
          => _keyValuePairs.GetEnumerator();

     IEnumerator IEnumerable.GetEnumerator()
          => this.GetEnumerator();
}

var envVarsProvider = new CustomProvider();
new EnvLoader()
         .SetEnvironmentVariablesProvider(envVarsProvider) // configuration method
         .Load();

string key1 = envVarsProvider["KEY1"];
string key2 = envVarsProvider["KEY2"];

When creating our own provider, the environment variables are not obtained from the current process, but from the custom provider (in this case it is a dictionary<string, string>).

Note: The IEnvironmentVariablesProvider interface is specific to the library.

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