ava-innersource / Liquid-Application-Framework-1.0-deprecated

Liquid is a framework to speed up the development of microservices
MIT License
25 stars 13 forks source link

Refactor duplicated environment checkings #106

Open guilhermeluizsp opened 4 years ago

guilhermeluizsp commented 4 years ago

There are duplicated snippets of code for checking the current environment of the application (by analyzing the _ASPNETCOREENVIRONMENT environment variable)

https://github.com/Avanade/Liquid-Application-Framework/blob/1d6c37c44fb5bbb6f84ba2f1d1a8a1b3d646c2ad/src/Liquid.Domain/API/LightApiMock.cs#L22-L24

https://github.com/Avanade/Liquid-Application-Framework/blob/1d6c37c44fb5bbb6f84ba2f1d1a8a1b3d646c2ad/src/Liquid.Runtime/Auth/AuthMiddleware.cs#L97-L101

https://github.com/Avanade/Liquid-Application-Framework/blob/1d6c37c44fb5bbb6f84ba2f1d1a8a1b3d646c2ad/src/Liquid.Runtime/Auth/JwtSecurityCustom.cs#L19-L26

https://github.com/Avanade/Liquid-Application-Framework/blob/1d6c37c44fb5bbb6f84ba2f1d1a8a1b3d646c2ad/src/Liquid.Runtime/Auth/JwtSecurityCustom.cs#L77-L81

https://github.com/Avanade/Liquid-Application-Framework/blob/1d6c37c44fb5bbb6f84ba2f1d1a8a1b3d646c2ad/src/Liquid.Runtime/Configuration/LiquidConfiguration.cs#L25-L27

https://github.com/Avanade/Liquid-Application-Framework/blob/1d6c37c44fb5bbb6f84ba2f1d1a8a1b3d646c2ad/src/Liquid.Runtime/Mock/MockData.cs#L19-L21

https://github.com/Avanade/Liquid-Application-Framework/blob/1d6c37c44fb5bbb6f84ba2f1d1a8a1b3d646c2ad/src/Liquid.Runtime/Mock/MockData.cs#L34-L37

This may lead to human mistakes since one could change the name "Quality" to "Staging" in one place and completely forgetting to update the other conditions.

We could leverage extension methods to make this kind of checks. IHostEnvironment and its former IHostingEnvironment both have extension methods to Development, Production and Staging scenarios. We could create our own extension method for Quality as well.

bruno-brant commented 4 years ago

I'm against "Quality". This is customer specific code, which we shouldn't support. Liquid should have two behaviors: production and non-production. Everything else should be controller by configuration files/environment variables.