Open vvdb-architecture opened 2 years ago
Quick question: Why do we need a special implementation at all? So what is the default .net implementation missing ?
We would not need it if we would align with .NET's way of labelling and managing environments.
For .Net Development is the local machine and Dev(elopment) is used by dev team to deploy and test the application on a server. This is why I have introduced the localhost concept which is more accurate for me.
Indeed, Localhost is a new environment specific for Elia, but the others could have been named like the predefined .NET constants. But, as mentioned in the original submission, they're might be political reasons why this is not a good suggestion.
The guidance currently generates this:
This is fragile because it is based on two undocumented assumptions:
The code only works because these undocumented assumptions happen to be correct.
We can debate if the removal of json-sources is really necessary, since they refer to optional
appsettings.json
/appsettings.{env}.json
, which do not exist anyway in the new deployment. Leaving them in might even be useful to keep them to allow for some "emergency reconfiguration" by simply adding anappsettings.json
in the base directory and restarting the project. But there may be security implications as well.If we must remove the sources, a more robust way of writing this can get rid of the first assumption, but not the second:
Note that:
.ToList()
We can go a little further and communicate to the host what the environment name is. If we do that, we can just re-add any existing json file to reflect the current base path, thereby getting rid of the second blind assumption:
The
.UseEnvironment(GetEnvironmentName()))
correctly propagates the environment to the host. After this, thehostingContext.HostingEnvironment.EnvironmentName
can be used to check the environment.On a related matter, the call to
GetEnvironmentName()
is currently defined as follows:There are predefined strings related to environment settings, which replace the magic string:
Finally there is code that checks if we are in a development scenario:
You expect this code to be execute in development contexts, including your local machine, but it won't: since the EnvironmentName is "Localhost" in that case and
app.Environment.IsDevelopment()
will return false.We should provide in Arc4u some methods that apply specifically to our environment names:
... so that we can check for them as well. Ideally, we should align our terminology with dotnet and talk about "Staging" instead of "Acceptance", but there might be political reasons why this is not a good suggestion.