dinotom
dinotom

Reputation: 5162

In Asp.net Core 2.0 is IHostingEnvironment extendable

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.

Upvotes: 3

Views: 492

Answers (1)

Evk
Evk

Reputation: 101613

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.

Upvotes: 5

Related Questions