Dosaic.Hosting.WebHost 1.2.53

dotnet add package Dosaic.Hosting.WebHost --version 1.2.53
                    
NuGet\Install-Package Dosaic.Hosting.WebHost -Version 1.2.53
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Dosaic.Hosting.WebHost" Version="1.2.53" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dosaic.Hosting.WebHost" Version="1.2.53" />
                    
Directory.Packages.props
<PackageReference Include="Dosaic.Hosting.WebHost" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Dosaic.Hosting.WebHost --version 1.2.53
                    
#r "nuget: Dosaic.Hosting.WebHost, 1.2.53"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Dosaic.Hosting.WebHost@1.2.53
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Dosaic.Hosting.WebHost&version=1.2.53
                    
Install as a Cake Addin
#tool nuget:?package=Dosaic.Hosting.WebHost&version=1.2.53
                    
Install as a Cake Tool

Dosaic.Hosting.WebHost

Nuget Nuget

Dosaic.Hosting.WebHost is the core orchestration package for any Dosaic-based service. It wires together plugin discovery, dependency injection, middleware pipeline configuration, health checks, OpenTelemetry, structured logging, CORS, response compression, IP rate limiting, and endpoint routing — all driven by the plugin interfaces from Dosaic.Hosting.Abstractions.

This package is mandatory. Without it no plugins can be loaded or configured.


Installation

dotnet add package Dosaic.Hosting.Generator  # required for AOT-compatible plugin discovery
dotnet add package Dosaic.Hosting.WebHost

Or as package references in your .csproj:

<PackageReference Include="Dosaic.Hosting.Generator" Version="" />
<PackageReference Include="Dosaic.Hosting.WebHost" Version="" />

Usage

Replace the content of Program.cs with:

using Dosaic.Hosting.WebHost;

PluginWebHostBuilder.RunDefault(Dosaic.Generated.DosaicPluginTypes.All);

DosaicPluginTypes.All is a Type[] emitted at compile time by Dosaic.Hosting.Generator — no runtime reflection scanning is required.

For advanced scenarios (e.g. integration testing) you can separate build from run:

using Dosaic.Hosting.WebHost;

var host = PluginWebHostBuilder.Create(Dosaic.Generated.DosaicPluginTypes.All, args).Build();
host.Run();

Features

Feature Details
AOT-compatible plugin discovery Plugin types resolved from source-generated Type[] — no reflection at runtime
Structured logging Serilog with span/thread enrichers, structured request logging
OpenTelemetry Metrics, tracing (OTLP), and logging exporters; Prometheus scraping endpoint at /metrics
Health checks Built-in liveness checks (API, disk, memory); plugin and attribute-driven registrations
CORS Configurable policy via CorsPolicy config section
Response compression Brotli + Gzip (fastest level), applied to HTTP and HTTPS
IP rate limiting AspNetCoreRateLimit integration, configurable via ipRateLimiting section
Layered configuration JSON, YAML, secrets files, env vars, CLI args — ordered by specificity
YAML input/output formatters Controllers accept and return application/yaml in addition to JSON
Forwarded headers All X-Forwarded-* headers applied when they come from loopback or a private network (Kubernetes ingress works without configuration), configurable via host:forwardedHeaders
Configurable Kestrel Listening URLs and max request body size controlled via config

Plugin Lifecycle

PluginWebHostBuilder.Build() executes the following phases in order:

1 — Host Configuration (HostConfigurator)

  • Clears default configuration sources and rebuilds them in the defined loading order (see Configuration below)
  • Configures Kestrel: listening URLs (host:urls), max request body size (host:maxRequestSize), server header suppression
  • Bootstraps Serilog structured logging

2 — Service Configuration (ServiceConfigurator)

  • Registers default services: JSON serialization, memory cache, datetime providers, forwarded headers
  • Configures CORS, response compression, IP rate limiting
  • Adds MVC controllers with YAML formatters and custom validation error responses
  • Discovers and registers [Configuration(...)]-attributed classes from IConfiguration
  • Registers health checks: built-in liveness checks + [HealthCheck]-attributed types + plugin-contributed checks
  • Configures OpenTelemetry metrics, tracing, and logging
  • Calls IPluginServiceConfiguration.ConfigureServices() on all discovered plugins (sorted by origin)

3 — App Build

WebApplicationBuilder.Build() finalises the DI container.

4 — Application Configuration (AppConfigurator)

  • Enables forwarded headers, response compression, IP rate limiting, CORS, Prometheus endpoint, routing
  • Registers [Middleware]-attributed types ordered by their Order property
  • Calls IPluginApplicationConfiguration.ConfigureApplication() on all discovered plugins
  • Maps health endpoints (/health/liveness, /health/readiness)
  • Maps controllers
  • Calls IPluginEndpointsConfiguration.ConfigureEndpoints() on all discovered plugins

5 — Instance Cleanup

TypeImplementationResolver.ClearInstances() disposes all plugin constructor instances created during build.

Plugin Sort Order

Plugin origin Sort key Runs
Dosaic.* namespace sbyte.MinValue First
Third-party plugins 0 Middle
Host assembly plugins sbyte.MaxValue Last

Configuration

Kestrel / Host

host:
  urls: "http://+:8080"          # default; separate multiple URLs with ","
  maxRequestSize: 8388608        # default 8 MB
  additionalConfigPaths: ""      # see "Additional Config Paths"
  healthChecks:
    memory:
      maximumMegabytes: 2048     # default; liveness threshold, 0 = no memory check (see "Health Endpoints")
  forwardedHeaders:              # see "Forwarded headers (reverse proxy, Kubernetes)"
    knownNetworks: "127.0.0.0/8,::1/128,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.64.0.0/10,fc00::/7"
    knownProxies: ""
    forwardLimit:                # empty = no limit

Environment variables (single _ maps to : hierarchy):

HOST_URLS=http://+:8080
HOST_MAXREQUESTSIZE=8388608
HOST_HEALTHCHECKS_MEMORY_MAXIMUMMEGABYTES=2048

The whole section is typed as HostConfiguration (Dosaic.Hosting.Abstractions.Configuration). The host reads it once, registers it as a singleton and hands the same instance to plugin constructors:

public class MyPlugin(HostConfiguration hostConfiguration) : IPluginServiceConfiguration
{
    public void ConfigureServices(IServiceCollection serviceCollection)
    {
        var limit = hostConfiguration.MaxRequestSize;                             // 8388608 unless configured
        var memory = hostConfiguration.HealthChecks.Memory.MaximumMegabytes;      // 2048 unless configured
    }
}
Key Property Default
host:urls Urls null → aspnetcore:urls → http://+:8080
host:maxRequestSize MaxRequestSize 8388608
host:additionalConfigPaths AdditionalConfigPaths null
host:healthChecks:memory:maximumMegabytes HealthChecks.Memory.MaximumMegabytes 2048, 0 = no check
host:forwardedHeaders:knownNetworks ForwardedHeaders.KnownNetworks loopback + private ranges (see below)
host:forwardedHeaders:knownProxies ForwardedHeaders.KnownProxies null
host:forwardedHeaders:forwardLimit ForwardedHeaders.ForwardLimit null = no limit

A missing host section, missing keys and explicit null values all keep the defaults.

Forwarded headers (reverse proxy, Kubernetes)

UseForwardedHeaders runs first in the pipeline and applies X-Forwarded-For (client IP), X-Forwarded-Proto (scheme), X-Forwarded-Host (host) and X-Forwarded-Prefix (moved into Request.PathBase). ASP.NET Core applies these headers only when the request comes from a trusted sender; by its own default that is loopback only, which ignores the headers of an ingress controller running in the cluster.

The web host therefore trusts loopback and the private address ranges by default:

Range Typical sender
127.0.0.0/8, ::1/128 sidecar proxy in the same pod
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 pod and node networks (ingress-nginx, Traefik, cloud load balancers in the VPC)
100.64.0.0/10 clusters whose pod network uses the carrier-grade NAT range
fc00::/7 IPv6 pod networks

A client on a public address cannot spoof the headers. With forwardLimit empty (default), the middleware walks the X-Forwarded-For chain back as long as the sender is trusted, so a cloud load balancer in front of the ingress controller works too, and a forged entry on the left of the chain is never reached.

Configure it when the defaults don't fit:

host:
  forwardedHeaders:
    knownNetworks: "10.42.0.0/16"       # replaces the defaults; only the pod network of the ingress
    knownProxies: "198.51.100.20"       # single addresses in addition
    forwardLimit: 2                     # at most two hops
HOST_FORWARDEDHEADERS_KNOWNNETWORKS=10.42.0.0/16
HOST_FORWARDEDHEADERS_KNOWNPROXIES=198.51.100.20
HOST_FORWARDEDHEADERS_FORWARDLIMIT=2

Values are separated by , or ;. 0.0.0.0/0,::/0 trusts every sender; use it only when nothing but the proxy can reach the pod. An invalid network, address or a limit below 1 stops the start.

Anything inside the cluster that can reach the pod directly is trusted by default. If other workloads in the cluster are not trusted, restrict knownNetworks to the ingress controller's network (or use a NetworkPolicy).

Path prefix. To serve the app below a prefix, let the proxy strip it and send X-Forwarded-Prefix. For ingress-nginx with a rewrite, set the annotation nginx.ingress.kubernetes.io/x-forwarded-prefix: /p/<slug>/api. Routes then match without the prefix, and links built from PathBase include it.

Configuration schema (editor completion)

Start the service with --write-config-schema [path] and it writes a JSON schema of its configuration instead of starting. The default path is appsettings.schema.json in the working directory. Files ending in .schema.json are never loaded as configuration, even though the name starts with appsettings.:

dotnet run -- --write-config-schema
dotnet run -- --write-config-schema ./config/appsettings.schema.json

The schema is built from the [Configuration] classes of the plugins the service is built with, plus the sections the web host reads itself (host, serilog, telemetry, CorsPolicy). It carries types, enum values, defaults and descriptions, so it always matches the installed packages.

  • It runs before anything is configured: no database, no connection strings and no valid configuration are needed.
  • The process arguments are read directly, so args do not have to be passed to PluginWebHostBuilder. A Program.cs that hands them to something else afterwards (.Build().RunWithGraphQLCommands(args)) works unchanged — the process ends before that code runs.
  • From code: PluginWebHostBuilder.WriteConfigurationSchema(DosaicPluginTypes.All, path).

To write the schema and carry on in the same process, set the environment variable DOSAIC_WRITE_CONFIG_SCHEMA to the path (true or 1 for the default file name) instead of passing the argument. The process then does whatever its arguments ask for, which is how two exports run in one go:

DOSAIC_WRITE_CONFIG_SCHEMA=appsettings.schema.json dotnet run -- schema export --output schema.graphql
Writes the schema Then
--write-config-schema [path] yes exits with code 0
DOSAIC_WRITE_CONFIG_SCHEMA=<path> yes continues with the given arguments, or starts the service when there are none

This has to be an environment variable: an extra argument would reach the command line parser of the next tool, which rejects what it does not know. It is meant for development and CI. An unchanged schema is not written again (no restart loop under dotnet watch), and a schema that cannot be written — read-only file system, missing permissions — is reported on standard error while the service starts anyway.

The host's args and the process arguments are read separately, so myapp serve --write-config-schema with args.Skip(1) handed to the host writes appsettings.schema.json and not a file named serve.

Reference the schema from the files that should get completion:

# yaml-language-server: $schema=./appsettings.schema.json
host:
  maxRequestSize: 8388608
{
  "$schema": "./appsettings.schema.json"
}

YAML completion needs an editor with the YAML language server (VS Code with the Red Hat YAML extension, JetBrains Rider). Commit the schema file and regenerate it after package updates.

Descriptions come from the XML documentation of the packages. NuGet does not copy those files to the output by default; add this to the service project to get them:

<PropertyGroup>
  <CopyDocumentationFilesFromPackages>true</CopyDocumentationFilesFromPackages>
</PropertyGroup>

What the schema cannot do:

  • Keys are offered in camel case. Configuration keys are not case sensitive, a JSON schema is — a key in another casing is not flagged, it just gets no completion.
  • Nothing is marked as required and unknown keys are allowed. Types are checked, which is stricter than the binder in places (it also accepts "5432" for a number). Enum names are completed as declared and accepted in any casing or as their number, like the binder does.
  • Sections with a name of your choice (for example RestEase clients) and third party sections (ipRateLimiting) are not described.
  • Environment variables get no completion.

Configuration File Loading Order

Dosaic loads configuration in the following order (later sources override earlier ones):

  1. appsettings.json
  2. appsettings.yaml / appsettings.yml
  3. appsettings.*.json
  4. appsettings.*.yaml / appsettings.*.yml
  5. appsettings.secrets.json / appsettings.secrets.yaml / appsettings.secrets.yml
  6. appsettings.*.secrets.json / appsettings.*.secrets.yaml / appsettings.*.secrets.yml
  7. Environment variables
  8. Command-line arguments

Files are sorted by node count (number of .-separated segments) within each group. Secrets files always load after non-secrets files. Files whose names do not start with appsettings are ignored.

Additional Config Paths

You can load configuration files from additional directories. Those files are loaded before the main application directory.

Via environment variable:

HOST_ADDITIONALCONFIGPATHS=/path/to/configs,/another/path

Via command-line argument:

dotnet run --HOST:ADDITIONALCONFIGPATHS "/path/to/configs,/another/path"
  • Subfolders are scanned recursively for appsettings.* files
  • Supports .json, .yaml, .yml formats
  • Non-existent paths raise a DirectoryNotFoundException
Environment Variable Mapping

Dosaic uses a custom provider that maps environment variable names to configuration keys by replacing _ with : (hierarchy separator). Double underscore __ is first collapsed to single _ before the mapping.

HOST_URLS              ->  host:urls
SERILOG_minimumLevel   ->  serilog:minimumLevel

Logging (Serilog)

serilog:
  minimumLevel: Information   # Verbose | Debug | Information | Warning | Error | Fatal
  override:
    System: Error
    Microsoft: Error

Environment variables:

SERILOG_minimumLevel=Information
SERILOG_OVERRIDE_SYSTEM=Error
SERILOG_OVERRIDE_MICROSOFT=Error

CORS

CorsPolicy:
  origins:
    - "https://example.com"
  methods:
    - "GET"
    - "POST"
  headers:
    - "*"
  exposedHeaders:
    - "*"

If any of origins, methods, headers, or exposedHeaders are not specified, they default to ["*"].

IP Rate Limiting

ipRateLimiting:
  enableEndpointRateLimiting: true
  generalRules:
    - endpoint: "*"
      period: "1s"
      limit: 50

ipRateLimitPolicies: {}

Refer to AspNetCoreRateLimit documentation for the full schema.

OpenTelemetry

When telemetry:endpoint is configured, traces, metrics, and logs are exported via OTLP. Log messages are enriched with SpanId and TraceId. Use telemetry:name to explicitly set the service name used by OpenTelemetry resources for traces, metrics, and logs.

telemetry:
  name: Dosaic.Example.Service    # optional OpenTelemetry service name
  endpoint: http://localhost:4317 # OTLP endpoint
  protocol: grpc                  # grpc (default) | http/protobuf, Grpc and HttpProtobuf work as well
  headers:
    - name: Authorization
      value: "Bearer <token>"

Without telemetry:endpoint, only the Prometheus scraping endpoint (/metrics) is active. No signal gets an OTLP exporter, so nothing is sent to the OpenTelemetry default http://localhost:4317.

telemetry:endpoint is the only switch for the OTLP export:

telemetry:endpoint OTEL_EXPORTER_OTLP_ENDPOINT Result
not set or empty set or not set No OTLP export of traces, metrics or logs. The variable is ignored.
set set or not set Traces, metrics and logs go to telemetry:endpoint. telemetry:protocol and telemetry:headers also replace OTEL_EXPORTER_OTLP_PROTOCOL and OTEL_EXPORTER_OTLP_HEADERS.

To use a collector from the environment, set TELEMETRY_ENDPOINT instead of OTEL_EXPORTER_OTLP_ENDPOINT.

telemetry:protocol takes the values of OTEL_EXPORTER_OTLP_PROTOCOL: grpc (default) and http/protobuf, in any casing, and the enum names Grpc and HttpProtobuf. Any other value stops the start when telemetry:endpoint is set. As OTEL_EXPORTER_OTLP_ENDPOINT would, telemetry:endpoint is the base URL:

telemetry:protocol telemetry:endpoint Traces, metrics, logs are sent to
grpc http://collector:4317 http://collector:4317 (the gRPC services)
http/protobuf http://collector:4318 http://collector:4318/v1/traces, /v1/metrics, /v1/logs
http/protobuf https://gateway/otlp/ https://gateway/otlp/v1/traces, /v1/metrics, /v1/logs

Metrics instrumentation (always active):

  • ASP.NET Core request metrics
  • HTTP client metrics
  • .NET runtime metrics
  • Process metrics
  • All custom Meters (*) plus the shared Dosaic meter (Tracing.SourceName)

Tracing instrumentation (requires telemetry:endpoint):

  • ASP.NET Core (Swagger paths excluded)
  • HTTP client
  • The shared Dosaic ActivitySource (Tracing.SourceName) — emit your own spans with Tracing.StartActivity(...); see Hosting/Abstractions/README.md
  • B3 propagation (single and multi-header)

Health Endpoints

Endpoint Tags filtered
GET /health/liveness liveness
GET /health/readiness readiness

Both endpoints return a JSON body:

{
  "status": "Healthy",
  "totalDuration": "00:00:00.012",
  "entries": [
    {
      "name": "api",
      "status": "Healthy",
      "description": null,
      "tags": ["liveness"],
      "duration": "00:00:00.001",
      "exceptionMessage": null
    }
  ]
}

Built-in liveness checks registered automatically:

Check Description
api Always healthy — confirms the process is running
disk_space Checks free space on all drives
memory Asserts allocated memory (GC.GetTotalMemory) is below the configured threshold, 2 GB by default

A failing liveness check makes Kubernetes restart the pod, so the memory threshold should match the memory limit of the deployment:

host:
  healthChecks:
    memory:
      maximumMegabytes: 2048     # default; 0 = do not register the memory check
HOST_HEALTHCHECKS_MEMORY_MAXIMUMMEGABYTES=6144

api and disk_space are always registered. A negative value stops the host at startup.

Plugins can contribute additional checks via IPluginHealthChecksConfiguration.ConfigureHealthChecks(). Custom checks can also be auto-discovered by implementing IHealthCheck and annotating the class with [HealthCheck("name", ...tags)].

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.53 72 11/16/2026
1.2.52 62 11/16/2026
1.2.51 68 11/13/2026
1.2.49 76 11/11/2026
1.2.48 89 11/4/2026
1.2.47 72 11/3/2026
1.2.45 80 10/30/2026
1.2.44 115 10/14/2026
1.2.43 99 10/13/2026
1.2.42 87 9/24/2026
1.2.41 104 9/7/2026
1.2.40 107 8/27/2026
1.2.40-alpha.1 84 8/27/2026
1.2.39 107 8/25/2026
1.2.38 104 7/30/2026
1.2.37 104 7/14/2026
1.2.36 101 7/10/2026
1.2.35 129 6/19/2026
1.2.34 96 6/10/2026
1.2.33 109 6/2/2026
Loading failed