-
Notifications
You must be signed in to change notification settings - Fork 50
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
Added a new Helper class #65
Conversation
@rogusdev Could you check this PR? Thanks. |
I see where you are going with this, and why. Honestly, I am a bit concerned about introducing something so different from how env vars are normally collected. Generally my personal recommendation is to have a class that collects all such values that you need in your application, and pass a version of that around as a mock/fake, instead of mocking out the env vars functionality of the language itself. That said, I can understand. So, my main questions is: are you sure about the index access? It seems like the get methods are the real way people should access such things. |
@rogusdev The indexer is just a simpler way to access the environment variable. It would be interesting that the library has a feature like this, it's like in PHP for example, you access the environment variables in this way: |
src/DotNetEnv/IEnvReader.cs
Outdated
{ | ||
get | ||
{ | ||
if (instance == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not thread safe. You should read up on how to make a singleton thread safe, if you really must have a singleton at all -- I strongly discourage it, personally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rogusdev To avoid complications, I have removed the property.
With this new functionality the
value
of the environment variable can be retrieved through the indexer:The advantage of this is that you can use dependency injection, either manually or by using a service container such as Microsoft.Extensions.DependencyInjection.
For example:
The
IEnvReader
interface also has some auxiliary methods to retrieve the value of an environment variable in a specific format (integer, double, etc.) and warns the client when it does not find the variable. It is true that currently the library already has this functionality but it does not warn the client when it does not find an environment variable.Methods that do not start with
Try
(asGetBoolValue
, etc.) throw an exception when the environment variable is not found. Methods that start withTry
(asTryGetBoolValue
), however, returnfalse
if the variable is not found, so the client has two options for handling the error.