CasCap.Common.Hosting.AspNetCore
4.15.0
Prefix Reserved
dotnet add package CasCap.Common.Hosting.AspNetCore --version 4.15.0
NuGet\Install-Package CasCap.Common.Hosting.AspNetCore -Version 4.15.0
<PackageReference Include="CasCap.Common.Hosting.AspNetCore" Version="4.15.0" />
<PackageVersion Include="CasCap.Common.Hosting.AspNetCore" Version="4.15.0" />
<PackageReference Include="CasCap.Common.Hosting.AspNetCore" />
paket add CasCap.Common.Hosting.AspNetCore --version 4.15.0
#r "nuget: CasCap.Common.Hosting.AspNetCore, 4.15.0"
#:package CasCap.Common.Hosting.AspNetCore@4.15.0
#addin nuget:?package=CasCap.Common.Hosting.AspNetCore&version=4.15.0
#tool nuget:?package=CasCap.Common.Hosting.AspNetCore&version=4.15.0
CasCap.Common.Hosting.AspNetCore
ASP.NET Core hosting defaults for feature-gated controllers, Serilog logging, and OpenTelemetry metrics, traces, and logs.
Installation
dotnet add package CasCap.Common.Hosting.AspNetCore
Feature-Gated Controllers
In a modular monolith the whole controller surface compiles into one process, but each deployment (pod/host) typically enables only a subset of features (see CasCap.Common.Services / FeatureFlagConfig.EnabledFeatures) and registers only that subset's services. Without gating, every controllers-enabled host maps every controller and returns HTTP 500 when a controller's feature-scoped dependency is not registered — and advertises endpoints in Swagger it cannot actually serve.
Mark a controller with [FeatureController(...)] and call AddFeatureGatedControllers(enabledFeatures) so the controller is only routed (and shown in OpenAPI/Swagger) on hosts where one of its features is enabled. Unmarked controllers are always available (their dependencies must be registered on every host that maps controllers).
This is the single-assembly (type-level) equivalent of gating controllers by
ApplicationPartat the assembly level. Prefer assembly-level gating (AddApplicationPartper enabled feature) when each feature's controllers live in their own assembly, since that also avoids loading off-feature assemblies.
Target frameworks: net8.0, net9.0, net10.0
Usage
// Controller — only mapped where the PafGen feature is enabled:
[ApiController]
[FeatureController(FeatureNames.PafGen)]
[Route("api/v{version:apiVersion}/paf/srzone")]
public sealed class SrZoneController(IPafPlotCollectionSource source) : ControllerBase { /* ... */ }
// Composition root:
builder.Services.AddControllers()
.AddFeatureGatedControllers(enabledFeatures); // same set passed to AddFeatureFlagService(...)
Types
| Type | Description |
|---|---|
FeatureControllerAttribute |
Marks a controller with the feature name(s) that must be enabled for it to be discovered. Unmarked = always available |
FeatureGatedControllerFeatureProvider |
IApplicationFeatureProvider<ControllerFeature> that prunes marked controllers whose feature is not enabled on the host |
Extensions
| Extension | Description |
|---|---|
MvcBuilderExtensions.AddFeatureGatedControllers() |
Adds the FeatureGatedControllerFeatureProvider to the MVC application-part manager for the supplied enabled-feature set |
Serilog
GetBootstrapLogger provides early startup logging, while InitializeSerilog configures Serilog as the host logging pipeline. Serilog owns the pipeline through UseSerilog(..., writeToProviders: true) so one Serilog configuration section controls the console and forwards events to Microsoft.Extensions.Logging providers, including OpenTelemetry.
| Extension | Description |
|---|---|
SerilogExtensions.GetBootstrapLogger() |
Creates a bootstrap console logger and wires ApplicationLogging.LoggerFactory |
SerilogWebApplicationBuilderExtensions.InitializeSerilog(builder, categoryName) |
Configures Serilog as the host pipeline and forwards events to registered logging providers |
LoggerConfiguration.AddCasCapDefaults(IConfiguration) |
Applies standard enrichers, console output, health-check filtering, and configuration binding |
SerilogExtensions.ConsoleLevelSwitch controls console verbosity independently from other sinks. It defaults to Verbose; interactive applications can temporarily raise it to Warning to prevent rendered output from interleaving with logs.
OpenTelemetry
InitializeOpenTelemetry registers metrics, traces, and logs with OTLP gRPC export. It uses IMetricsConfig for the service name, metric prefix, and exporter endpoint.
| Extension | Description |
|---|---|
OpenTelemetryExtensions.InitializeOpenTelemetry(...) |
Registers OpenTelemetry metrics, traces, and logs with OTLP gRPC export |
MeterProviderBuilderExtensions.AddHistogramView(...) |
Registers explicit histogram bucket boundaries for a prefixed instrument |
MetricBoundaries.Symmetric(...) |
Mirrors positive boundaries into a signed set around zero |
Registration is skipped when IMetricsConfig.OtlpExporterEndpoint is null. Development hosts expose the Prometheus exporter; non-development hosts add ASP.NET Core, runtime, process, HTTP client, and optional Redis instrumentation.
Configuration Examples
Minimal configuration disables telemetry:
{
"AppConfig": {
"MetricNamePrefix": "app",
"OtelServiceName": "Example.App"
}
}
Configured OTLP export:
{
"AppConfig": {
"MetricNamePrefix": "app",
"OtelServiceName": "Example.App",
"OtlpExporterEndpoint": "http://otel-collector.example.com:4317"
}
}
Dependencies
Framework References
| Reference | Purpose |
|---|---|
Microsoft.AspNetCore.App |
ASP.NET Core MVC application-part / controller-feature types (IApplicationFeatureProvider<ControllerFeature>, IMvcBuilder) |
Project References
| Project | Purpose |
|---|---|
CasCap.Common.Abstractions |
Host and metrics configuration contracts |
CasCap.Common.Logging |
Shared ApplicationLogging logger factory |
CasCap.Common.Net |
Basic-auth header creation for authenticated OTLP exporters |
CasCap.Common.Services |
Git build metadata for telemetry resource attributes |
NuGet Packages
The package includes the Serilog ASP.NET Core pipeline, standard Serilog enrichers and console sink, OpenTelemetry hosting/export packages, ASP.NET Core, HTTP, process, runtime, and Redis instrumentation, and StackExchange.Redis integration.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
-
net10.0
- CasCap.Common.Abstractions (>= 4.15.0)
- CasCap.Common.Logging (>= 4.15.0)
- CasCap.Common.Net (>= 4.15.0)
- CasCap.Common.Services (>= 4.15.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.19.1)
- OpenTelemetry.Exporter.Prometheus.AspNetCore (>= 1.17.0-beta.1)
- OpenTelemetry.Extensions.Hosting (>= 1.19.1)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.19.0)
- OpenTelemetry.Instrumentation.Http (>= 1.19.0)
- OpenTelemetry.Instrumentation.Process (>= 1.17.0-rc.1)
- OpenTelemetry.Instrumentation.Runtime (>= 1.19.0)
- OpenTelemetry.Instrumentation.StackExchangeRedis (>= 1.17.0-beta.1)
- Serilog (>= 4.4.0)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Enrichers.AssemblyName (>= 2.0.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Span (>= 3.1.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Exceptions (>= 8.4.0)
- Serilog.Extensions.Hosting (>= 10.0.0)
- Serilog.Extensions.Logging (>= 10.0.0)
- Serilog.Settings.Configuration (>= 10.0.1)
- Serilog.Sinks.Console (>= 6.1.1)
- StackExchange.Redis (>= 3.3.1)
-
net8.0
- CasCap.Common.Abstractions (>= 4.15.0)
- CasCap.Common.Logging (>= 4.15.0)
- CasCap.Common.Net (>= 4.15.0)
- CasCap.Common.Services (>= 4.15.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.19.1)
- OpenTelemetry.Exporter.Prometheus.AspNetCore (>= 1.17.0-beta.1)
- OpenTelemetry.Extensions.Hosting (>= 1.19.1)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.19.0)
- OpenTelemetry.Instrumentation.Http (>= 1.19.0)
- OpenTelemetry.Instrumentation.Process (>= 1.17.0-rc.1)
- OpenTelemetry.Instrumentation.Runtime (>= 1.19.0)
- OpenTelemetry.Instrumentation.StackExchangeRedis (>= 1.17.0-beta.1)
- Serilog (>= 4.4.0)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Enrichers.AssemblyName (>= 2.0.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Span (>= 3.1.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Exceptions (>= 8.4.0)
- Serilog.Extensions.Hosting (>= 10.0.0)
- Serilog.Extensions.Logging (>= 10.0.0)
- Serilog.Settings.Configuration (>= 10.0.1)
- Serilog.Sinks.Console (>= 6.1.1)
- StackExchange.Redis (>= 3.3.1)
-
net9.0
- CasCap.Common.Abstractions (>= 4.15.0)
- CasCap.Common.Logging (>= 4.15.0)
- CasCap.Common.Net (>= 4.15.0)
- CasCap.Common.Services (>= 4.15.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.19.1)
- OpenTelemetry.Exporter.Prometheus.AspNetCore (>= 1.17.0-beta.1)
- OpenTelemetry.Extensions.Hosting (>= 1.19.1)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.19.0)
- OpenTelemetry.Instrumentation.Http (>= 1.19.0)
- OpenTelemetry.Instrumentation.Process (>= 1.17.0-rc.1)
- OpenTelemetry.Instrumentation.Runtime (>= 1.19.0)
- OpenTelemetry.Instrumentation.StackExchangeRedis (>= 1.17.0-beta.1)
- Serilog (>= 4.4.0)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Enrichers.AssemblyName (>= 2.0.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Span (>= 3.1.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Exceptions (>= 8.4.0)
- Serilog.Extensions.Hosting (>= 10.0.0)
- Serilog.Extensions.Logging (>= 10.0.0)
- Serilog.Settings.Configuration (>= 10.0.1)
- Serilog.Sinks.Console (>= 6.1.1)
- StackExchange.Redis (>= 3.3.1)
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 |
|---|---|---|
| 4.15.0 | 62 | 10/6/2026 |