You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bind is just a method of the EnvBinder class and would be responsible for binding the provider environment variables to the configuration class (in this case it would be AppSettings).
Of course, for the above code to work, the .env file should look like this:
In fact, there is no standard that tells us how to write the key names in an .env file, there is none. Normally a convention is followed:
# UpperCase + SnakeCaseKEY_NAME=VALUE
But it is not mandatory. Each project may name the keys in one way or another.
You may want to name your keys using this convention: KEY_NAME=VALUE (UpperCase + SnakeCase) and at the same time you want to name the properties in Pascal Case, therefore, you will have to associate an attribute (or decorator) to each property of the configuration class:
It is necessary to embed the name of the real key to each property, since this way the EnvBinder.Bind method will be able to access the real key and set the value in the property.
The EnvKey attribute should only be used when the writing style of the keys of an .env file does not match that of the properties of a class (such as AppSettings).
The text was updated successfully, but these errors were encountered:
It would be nice if the keys could be accessed through a configuration class, for example:
Bind
is just a method of theEnvBinder
class and would be responsible for binding the provider environment variables to the configuration class (in this case it would beAppSettings
).Of course, for the above code to work, the .env file should look like this:
In fact, there is no standard that tells us how to write the key names in an .env file, there is none. Normally a convention is followed:
But it is not mandatory. Each project may name the keys in one way or another.
You may want to name your keys using this convention:
KEY_NAME=VALUE
(UpperCase + SnakeCase) and at the same time you want to name the properties in Pascal Case, therefore, you will have to associate an attribute (or decorator) to each property of the configuration class:It is necessary to embed the name of the real key to each property, since this way the
EnvBinder.Bind
method will be able to access the real key and set the value in the property.The
EnvKey
attribute should only be used when the writing style of the keys of an .env file does not match that of the properties of a class (such asAppSettings
).The text was updated successfully, but these errors were encountered: