Liquid-Application-Framework-1.0-deprecated icon indicating copy to clipboard operation
Liquid-Application-Framework-1.0-deprecated copied to clipboard

Refactor duplicated environment checkings

Open guilhermeluizsp opened this issue 5 years ago • 1 comments

There are duplicated snippets of code for checking the current environment of the application (by analyzing the ASPNETCORE_ENVIRONMENT 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.

guilhermeluizsp avatar Nov 30 '19 03:11 guilhermeluizsp