HostEnvironmentExtensions Class
Definition
- Namespace
- Cuemon.Extensions.Hosting
- Assemblies
- 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.
// Program.cs
using System;
using Cuemon.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using var host = Host.CreateDefaultBuilder()
.UseEnvironment(Cuemon.Extensions.Hosting.Environments.LocalDevelopment)
.Build();
var environment = host.Services.GetRequiredService<IHostEnvironment>();
if (environment.IsLocalDevelopment())
{
Console.WriteLine("Running on a developer machine.");
}
if (environment.IsNonProduction())
{
Console.WriteLine("Environment is not Production.");
}
Methods
| Name | Description |
|---|---|
| IsLocalDevelopment(IHostEnvironment) | Determines whether the specified |
| IsNonProduction(IHostEnvironment) | Determines whether the specified |