@@ -6,6 +6,7 @@ public static class Environments
66 public static readonly string Development = "dev" ;
77 public static readonly string Staging = "staging" ;
88 public static readonly string Production = "production" ;
9+ public static readonly string MvpDevelopment = "mvp-dev" ; // Not in use but should be
910 public static readonly string MvpStaging = "mvp-staging" ;
1011 public static readonly string MvpProduction = "mvp-production" ;
1112}
@@ -14,41 +15,73 @@ public static class EnvironmentExtensions
1415{
1516 public static bool IsLocal ( this IHostEnvironment hostEnvironment )
1617 {
17- if ( hostEnvironment == null )
18- {
19- throw new ArgumentNullException ( nameof ( hostEnvironment ) ) ;
20- }
21-
22- return hostEnvironment . IsEnvironment ( Environments . Local ) ;
18+ return IsEnvironment ( hostEnvironment , Environments . Local ) ;
2319 }
2420
21+ //
22+ // Non-MVP app environments
23+ //
2524 public static bool IsDevelopment ( this IHostEnvironment hostEnvironment )
2625 {
27- if ( hostEnvironment == null )
28- {
29- throw new ArgumentNullException ( nameof ( hostEnvironment ) ) ;
30- }
31-
32- return hostEnvironment . IsEnvironment ( Environments . Development ) ;
26+ return IsEnvironment ( hostEnvironment , Environments . Development ) ;
3327 }
3428
3529 public static bool IsStaging ( this IHostEnvironment hostEnvironment )
3630 {
37- if ( hostEnvironment == null )
38- {
39- throw new ArgumentException ( null , nameof ( hostEnvironment ) ) ;
40- }
41-
42- return hostEnvironment . IsEnvironment ( Environments . MvpStaging ) || hostEnvironment . IsEnvironment ( Environments . Staging ) ;
31+ return IsEnvironment ( hostEnvironment , Environments . Staging ) ;
4332 }
4433
4534 public static bool IsProduction ( this IHostEnvironment hostEnvironment )
35+ {
36+ return IsEnvironment ( hostEnvironment , Environments . Production ) ;
37+ }
38+
39+ // Production-like environments are staging and production
40+ public static bool IsProductionlike ( this IHostEnvironment hostEnvironment )
41+ {
42+ return IsProduction ( hostEnvironment ) || IsStaging ( hostEnvironment ) ;
43+ }
44+
45+ //
46+ // MVP app environments
47+ //
48+ public static bool IsMvpDevelopment ( this IHostEnvironment hostEnvironment )
49+ {
50+ return IsEnvironment ( hostEnvironment , Environments . MvpDevelopment ) ;
51+ }
52+
53+ public static bool IsMvpStaging ( this IHostEnvironment hostEnvironment )
54+ {
55+ return IsEnvironment ( hostEnvironment , Environments . MvpStaging ) ;
56+ }
57+
58+ public static bool IsMvpProduction ( this IHostEnvironment hostEnvironment )
59+ {
60+ return IsEnvironment ( hostEnvironment , Environments . MvpProduction ) ;
61+ }
62+
63+ // MVP production-like environments are MVP staging and MVP production
64+
65+ public static bool IsMvpProductionlike ( this IHostEnvironment hostEnvironment )
66+ {
67+ return IsMvpProduction ( hostEnvironment ) || IsMvpStaging ( hostEnvironment ) ;
68+ }
69+
70+ //
71+ // Helper methods
72+ //
73+ public static bool IsMvpEnvironment ( this IHostEnvironment hostEnvironment )
74+ {
75+ return IsMvpProduction ( hostEnvironment ) || IsMvpStaging ( hostEnvironment ) || IsMvpDevelopment ( hostEnvironment ) ;
76+ }
77+
78+ public static bool IsEnvironment ( IHostEnvironment hostEnvironment , string environmentName )
4679 {
4780 if ( hostEnvironment == null )
4881 {
49- throw new ArgumentException ( null , nameof ( hostEnvironment ) ) ;
82+ throw new ArgumentNullException ( nameof ( hostEnvironment ) ) ;
5083 }
5184
52- return hostEnvironment . IsEnvironment ( Environments . MvpProduction ) || hostEnvironment . IsEnvironment ( Environments . Production ) ;
85+ return hostEnvironment . IsEnvironment ( environmentName ) ;
5386 }
5487}
0 commit comments