Skip to content
Documentation

Service Class

Base class for HTTP services.

public abstract class Service : System.IAsyncDisposable

Inheritance System.Object 🡒 Service

Derived
↳ Service<TSettingsClass,TSettingsInterface>

Implements System.IAsyncDisposable

This class is provided to take some of the common boiler-plate code off the developers hands.

Override any of the virtual methods to modify the services behavior.

The methods are called in the following order:

  1. ConfigureBuilder(WebApplicationBuilder)
  2. ConfigureHakomServices(IContainer, IConfiguration)
  3. ConfigureLogging(ILoggingBuilder)
  4. ConfigureMvc(IMvcBuilder)
  5. ConfigureApplication(WebApplication)

Please note that ConfigureBuilder(WebApplicationBuilder) invokes ConfigureHealthChecks(IHealthChecksBuilder).

Initializes a new instance of Service.

protected Service();

The base URL to host the service under if nothing else is configured.

public const string DEFAULT_URLS = "http://localhost:5000";

System.String

Tag that identifies a health check as part of the liveness probe.

protected const string HEALTHCHECK_LIVE_TAG = "live";

System.String

Tag that identifies a health check as part of the readiness probe.

protected const string HEALTHCHECK_READY_TAG = "ready";

System.String

The root node of the configuration used.

protected virtual Microsoft.Extensions.Configuration.IConfiguration ConfigurationRoot { protected get; }

Microsoft.Extensions.Configuration.IConfiguration

The settings that determine health check behavior (e.g. timeout of graceful shutdown)

protected HAKOM.Http.Core.Net.Api.IHealthCheckSettings HealthCheckSettings { protected get; }

IHealthCheckSettings

The settings that determine basic/common hosting behavior (URLs, CORS, SSL, etc).

protected HAKOM.Http.Core.Net.Api.IHostingSettings HostingSettings { protected get; }

IHostingSettings

Gets the name of this service, used to locate its configuration section.

public abstract string Name { get; }

System.String

The configuration section that holds all the settings for the service.

protected virtual Microsoft.Extensions.Configuration.IConfigurationSection ServiceConfiguration { protected get; }

Microsoft.Extensions.Configuration.IConfigurationSection

Once the service is running, this property will return the URLs under which it can be accessed.

public System.Collections.Generic.IEnumerable<string> Urls { get; }

System.Collections.Generic.IEnumerable<System.String>

Service.ConfigureApplication(WebApplication) Method

Section titled “Service.ConfigureApplication(WebApplication) Method”

Configures the Microsoft.AspNetCore.Builder.WebApplication middleware pipeline.

protected virtual void ConfigureApplication(Microsoft.AspNetCore.Builder.WebApplication application);

application Microsoft.AspNetCore.Builder.WebApplication

The Microsoft.AspNetCore.Builder.WebApplication to configure.

Override to add custom middleware. Always call base.ConfigureApplication to apply HAKOM defaults (Accept header injection, forwarded headers, compression, localisation, HTTPS redirect, exception handling).

Service.ConfigureBuilder(WebApplicationBuilder) Method

Section titled “Service.ConfigureBuilder(WebApplicationBuilder) Method”

Takes care of setting up configuration, logging, being able to run the service as a daemon/Windows service, and a few other things.

protected virtual Microsoft.Extensions.DependencyInjection.IMvcBuilder? ConfigureBuilder(Microsoft.AspNetCore.Builder.WebApplicationBuilder builder);

builder Microsoft.AspNetCore.Builder.WebApplicationBuilder

The Microsoft.AspNetCore.Builder.WebApplicationBuilder used to build the service.

Microsoft.Extensions.DependencyInjection.IMvcBuilder
The instance of Microsoft.Extensions.DependencyInjection.IMvcBuilder used to configure the MVC framework. This will be passed to ConfigureMvc(IMvcBuilder)

When overriding this method, make sure to call the base method!

Service.ConfigureHakomServices(IContainer, IConfiguration) Method

Section titled “Service.ConfigureHakomServices(IContainer, IConfiguration) Method”

Registers HAKOM services and resolves hosting configuration from the DI container.

protected virtual void ConfigureHakomServices(HAKOM.DependencyInjection.Core.Net.Api.IContainer container, out Microsoft.Extensions.Configuration.IConfiguration? hostConfiguration);

container IContainer

The DI container to register services into.

hostConfiguration Microsoft.Extensions.Configuration.IConfiguration

When this method returns, contains the resolved Microsoft.Extensions.Configuration.IConfiguration for the hosting section, or null if no host configuration was found.

Override this method in derived classes to register additional services. Always call base.ConfigureHakomServices.

Service.ConfigureHealthChecks(IHealthChecksBuilder) Method

Section titled “Service.ConfigureHealthChecks(IHealthChecksBuilder) Method”

Override to register additional Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck implementations. Always call base.ConfigureHealthChecks to retain the built-in checks. Tag a check with HEALTHCHECK_READY_TAG to have it evaluated by /health/ready, or HEALTHCHECK_LIVE_TAG for /health/live.

protected virtual void ConfigureHealthChecks(Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder healthChecksBuilder);

healthChecksBuilder Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder

The Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder used to register Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck implementations.

Service.ConfigureLogging(ILoggingBuilder) Method

Section titled “Service.ConfigureLogging(ILoggingBuilder) Method”

Configures the logging pipeline for the service.

protected virtual void ConfigureLogging(Microsoft.Extensions.Logging.ILoggingBuilder loggingBuilder);

loggingBuilder Microsoft.Extensions.Logging.ILoggingBuilder

The Microsoft.Extensions.Logging.ILoggingBuilder to configure.

Override to customise log providers. The default implementation reads the {Name}:Http:Logging configuration section.

Configures MVC application parts for the service.

protected virtual void ConfigureMvc(Microsoft.Extensions.DependencyInjection.IMvcBuilder mvcBuilder);

mvcBuilder Microsoft.Extensions.DependencyInjection.IMvcBuilder

The Microsoft.Extensions.DependencyInjection.IMvcBuilder to configure.

Override to add additional application parts or adjust MVC options. Always call base.ConfigureMvc to register the service assembly.

Releases resources held by the service, including the underlying Microsoft.AspNetCore.Builder.WebApplication.

public System.Threading.Tasks.ValueTask DisposeAsync();

Implements DisposeAsync()

System.Threading.Tasks.ValueTask
A System.Threading.Tasks.ValueTask that completes once all resources have been disposed.

Starts the service and blocks until it is stopped.

public System.Threading.Tasks.Task Run();

System.Threading.Tasks.Task
A task that completes when the service shuts down.

Initializes the service.

public void Setup(string[] args);

args System.String[]

Command line parameters.

System.InvalidOperationException
Thrown if no application parts where registered. Make sure to call base.ConfigureMvc from its overridden implementation in order to use controllers from the current assembly or manually add one or more application parts manually (i.e. by calling AddPrefixedApplicationPart(this IMvcBuilder, IEnumerable<TypeInfo>, string, string).

Starts the service without blocking, allowing the caller to continue execution.

public System.Threading.Tasks.Task Start();

System.Threading.Tasks.Task
A task that completes once the service has started listening.

Gracefully stops a service that was started with Start().

public System.Threading.Tasks.Task Stop();

System.Threading.Tasks.Task
A task that completes once the service has stopped.

© 2026 Volue.Version v0.6.38017 November 2026