Table of Contents

Application

Description

Entry point for starting and stopping the host. Wraps ASP.NET host setup into three startup approaches depending on how much control you need.

Features

  • Three startup APIs: Start, Build, and Extension — from zero-config to full control
  • Hook support: IFrameworkHooks callbacks throughout the host lifecycle
  • Async support: All startup methods have async variants

Behavior

Start API

Simplest approach — framework manages the full host lifecycle:

var options = new FrameworkOptions();
Application.Start<Hooks>(AppType.Web, options, AppHosting.Kestrel, urls);

Build API

Returns the host builder for additional configuration before running:

var options = new FrameworkOptions();
var builder = Application.Build<Hooks>(AppType.Web, options, AppHosting.Kestrel,  urls);
var app = builder.Build();
app.Run();

Extension API

Full control via extension methods directly on the host builder. IFrameworkHooks is not invoked in this mode:

var builder = Host.CreateDefaultBuilder(args);
builder.ConfigureServices((context, services) => {
    services = services.AddFrameworkServices(AppType.Web);
});
builder = builder.ConfigureWebHostDefaults(webBuilder => {
    webBuilder.UseKestrel();
    webBuilder.Configure(app => {
        app.UseFrameworkBeginMiddlewares(AppType.Web);
        // ...
        app.UseFrameworkEndMiddlewares(AppType.Web);
    });
});
var app = builder.Build();
app.Run();

Stopping the host

Application.HostStop();
// or
await Application.HostStopAsync();

Caveats

  • Calling Start or StartAsync twice throws InvalidOperationException — only one host instance is allowed
  • IFrameworkHooks is not invoked when using the Framework Extension API
Tip
  • Use Application.Start for most applications. Use Application.Build if you need to configure the host after building. Use the Extension API if you're integrating into an existing host setup or you need full control.
  • Modules work without registering middleware: Log, Cache, Client, Encryption, Json and Config

AppSettings

View all appsettings here