On 19/11/2024 13:26, John D'Orazio wrote:
I don't understand why an application should not know which
environment it is running in?
I don't know if this list is the place to be discussing this, but here goes:
Typically you are injecting the environment name to have the application
switch to a different configuration to load a whole bunch of different
settings for that environment. Instead, you should be injecting all
those different settings directly. The reason is because otherwise you
are tightly coupling your application to a fixed number of known
environments, limiting deployment options. Instead, the application
should be environment agnostic, thereby enabling whomsoever deploys your
application to configure as many different environment types as they wish.
This best practice also avoids the temptation to code different logic
paths based on the environment name (very bad).
Don't worry, this is a common mistake, and even popular frameworks like
Laravel and Symfony promote this anti-pattern to some degree.
Cheers,
Bilge