On Tue, Nov 19, 2024, 6:38 a.m. Bilge <bi...@scriptfusion.com> wrote:
> 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 > So if symfony and laravel do this, whose best practices are we going by exactly, yours? Switching configuration is one of many reasons an app needs to know what environment it's running on. What if I want more verbose logging at dev time? Or want to bypass expensive api calls with mock data? Or want to make sure something is never called in production? Cheers, Hammed >