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
environmentIHostEnvironmentThe IHostingEnvironment to extend.
Returns
- bool
trueifenvironmentisLocalDevelopment; otherwisefalse
IsNonProduction(IHostEnvironment)
Determines whether the specified environment is different from Production.
public static bool IsNonProduction(this IHostEnvironment environment)
Parameters
environmentIHostEnvironmentThe IHostingEnvironment to extend.
Returns
- bool
trueifenvironmentis notProduction; otherwisefalse