Table of Contents

Class HostingEnvironmentOptions

Namespace
Cuemon.AspNetCore.Hosting
Assembly
Cuemon.AspNetCore.dll

Configuration options for HostingEnvironmentMiddleware.

public class HostingEnvironmentOptions : IValidatableParameterObject, IParameterObject
Inheritance
HostingEnvironmentOptions
Implements

Examples

The following example demonstrates how to configure hosting environment options.

using System;
using Microsoft.Extensions.Hosting;

        namespace Cuemon.AspNetCore.Hosting;

        public static class HostingEnvironmentOptionsExample
        {
            public static void Demonstrate()
            {
                var options = new HostingEnvironmentOptions
        {
            HeaderName = "X-Environment",
            SuppressHeaderPredicate = environment => environment.IsProduction()
        };

        options.ValidateOptions();
        Console.WriteLine(options.HeaderName);
            }
        }

Constructors

HostingEnvironmentOptions()

Initializes a new instance of the HostingEnvironmentOptions class.

public HostingEnvironmentOptions()

Remarks

The following table shows the initial property values for an instance of HostingEnvironmentOptions.

PropertyInitial Value
HeaderNameX-Hosting-Environment
SuppressHeaderPredicateenvironment => environment.IsProduction()

Properties

HeaderName

Gets or sets the name of the hosting environment HTTP header.

public string HeaderName { get; set; }

Property Value

string

The name of the hosting environment HTTP header.

SuppressHeaderPredicate

Gets or sets the predicate that can suppress the hosting environment HTTP header.

public Func<IHostEnvironment, bool> SuppressHeaderPredicate { get; set; }

Property Value

Func<IHostEnvironment, bool>

The function delegate that can determine if the hosting environment HTTP header should be suppressed.

Methods

ValidateOptions()

Determines whether the public read-write properties of this instance are in a valid state.

public void ValidateOptions()

Remarks

This method is expected to throw exceptions when one or more conditions fails to be in a valid state.

Exceptions

InvalidOperationException

HeaderName cannot be null, empty or consist only of white-space characters - or - SuppressHeaderPredicate cannot be null.