Table of Contents

Class HostEnvironmentExtensions

Namespace
Cuemon.Extensions.Hosting
Assembly
Cuemon.Extensions.Hosting.dll

Extension methods for the IHostEnvironment interface.

public static class HostEnvironmentExtensions
Inheritance
HostEnvironmentExtensions

Examples

HostEnvironmentExtensions provides extension methods for IHostEnvironment to check whether the current environment is a local development or non-production environment. This example takes an IHostEnvironment parameter and calls IsLocalDevelopment() to detect a developer machine and IsNonProduction() to check for any non-production environment. Key setup includes using these methods in conditional startup logic. Console output prints "Running on a developer machine." or "Environment is not Production." based on the check results.

using System;
using Cuemon.Extensions.Hosting;
using Microsoft.Extensions.Hosting;

namespace MyApp.Startup;

public class EnvironmentReporter
{
    public void Report(IHostEnvironment env)
    {
        if (env.IsLocalDevelopment())
        {
            Console.WriteLine("Running on a developer machine.");

        if (env.IsNonProduction())
        {
            Console.WriteLine("Environment is not Production.");

}}}
}

Methods

IsLocalDevelopment(IHostEnvironment)

Determines whether the specified environment is equal to LocalDevelopment.

public static bool IsLocalDevelopment(this IHostEnvironment environment)

Parameters

environment IHostEnvironment

The IHostingEnvironment to extend.

Returns

bool

true if environment is LocalDevelopment; otherwise false

IsNonProduction(IHostEnvironment)

Determines whether the specified environment is different from Production.

public static bool IsNonProduction(this IHostEnvironment environment)

Parameters

environment IHostEnvironment

The IHostingEnvironment to extend.

Returns

bool

true if environment is not Production; otherwise false