Currently, Asp.Net core 2 IHostingEnvironment has three boolean properties
is it extendable if I wanted to create two additional properties? (e.g. IsTesting, IsCloudDb)
Since I am not a professional programmer I'm not sure how to go about this IF it is doable.
Those are not properties but extension methods for IHostingEnvironment interface. All those extension methods do is compare IHostingEnvironment.EnvironmentName with predefined string. You can do the same:
public static class EnvironmentExtensions {
const string CloudDbEnvironment = "CloudDb";
const string TestingEnvironment = "Testing";
public static bool IsCloudDb(this IHostingEnvironment env) {
return env.IsEnvironment(CloudDbEnvironment);
}
public static bool IsTesting(this IHostingEnvironment env) {
return env.IsEnvironment(TestingEnvironment);
}
}
Of course you should set EnvironmentName to the related string for those methods to return true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With