KestrunHost class

Provides hosting and configuration for the Kestrun application, including service registration, middleware setup, and runspace pool management.

public class KestrunHost : IDisposable

Public Members

name description
KestrunHost(…) Initializes a new instance of the KestrunHost class with the specified application name, root directory, and optional module paths. (2 constructors)
ApplicationName { get; } Gets the application name for the Kestrun host.
DefaultCacheControl { get; } Gets or sets the default cache control settings for HTTP responses.
DefaultHost { get; } Gets or sets a value indicating whether this instance is the default Kestrun host.
ExceptionOptions { get; set; } Gets or sets the exception options for configuring exception handling.
ForwardedHeaderOptions { get; set; } Gets or sets the forwarded headers options for configuring forwarded headers handling.
IsConfigured { get; } Indicates whether the Kestrun host configuration has been applied.
IsRunning { get; } Determines whether the Kestrun web application is currently running.
KestrunRoot { get; } Gets the root directory path for the Kestrun application.
Logger { get; } Gets the Serilog logger instance used by the Kestrun host.
Options { get; } Gets the configuration options for the Kestrun host.
PowershellMiddlewareEnabled { get; set; } Gets the shared state manager for managing shared data across requests and sessions.
RegisteredAuthentications { get; } Gets the registered authentication schemes in the Kestrun host.
RegisteredRoutes { get; } Gets the registered routes in the Kestrun host.
RouteGroupStack { get; } Gets the stack used for managing route groups in the Kestrun host.
Scheduler { get; } Gets the scheduler service used for managing scheduled tasks in the Kestrun host.
StartTime { get; } Gets the timestamp when the Kestrun host was started.
StatusCodeOptions { get; set; } Gets or sets the status code options for configuring status code pages.
StopTime { get; } Gets the timestamp when the Kestrun host was stopped.
Tasks { get; } Gets the ad-hoc task service used for running one-off tasks (PowerShell, C#, VB.NET).
Uptime { get; } Gets the uptime duration of the Kestrun host. While running (no StopTime yet), this returns DateTime.UtcNow - StartTime. After stopping, it returns StopTime - StartTime. If StartTime is not set, returns null.
AddControllers(…) Adds MVC / API controllers to the application.
AddFeature(…) Adds a feature configuration action to the feature queue. This action will be executed when the features are applied.
AddPowerShellRuntime(…) Adds a PowerShell runtime to the application. This middleware allows you to execute PowerShell scripts in response to HTTP requests.
AddProbe(…) Registers the provided IProbe instance with the host. (3 methods)
AddScheduling(…) Adds a scheduling feature to the Kestrun host, optionally specifying the maximum number of runspaces for the scheduler.
AddService(…) Adds a service configuration action to the service queue. This action will be executed when the services are built.
AddSignalR(…) Adds the default SignalR hub (KestrunHub) to the application at the specified path.
AddSignalR<T>(…) Adds a SignalR hub to the application at the specified path.
AddTasks(…) Adds the Tasks feature to run ad-hoc scripts with status/result/cancellation.
Build() Builds the WebApplication. This method applies all queued services and middleware stages, and returns the built WebApplication instance.
ConfigureListener(…) Configures a listener for the Kestrun host with the specified port, optional IP address, certificate, protocols, and connection logging. (5 methods)
CreateRunspacePool(…) Creates and returns a new KestrunRunspacePoolManager instance with the specified maximum number of runspaces.
Dispose() Releases all resources used by the KestrunHost instance.
EnableConfiguration(…) Applies the configured options to the Kestrel server and initializes the runspace pool.
IsServiceRegistered(…) Returns true if the specified service type has already been registered in the IServiceCollection.
IsServiceRegistered<TService>() Generic convenience overload.
Run() Runs the Kestrun web application, applying configuration and starting the server.
StartAsync(…) Starts the Kestrun web application asynchronously.
Stop() Initiates a graceful shutdown of the Kestrun web application.
StopAsync(…) Stops the Kestrun web application asynchronously.
Use(…) Adds a middleware stage to the application pipeline.

See Also