Application
Entry point for starting and stopping the framework host. The class wraps ASP.NET host creation and exposes several startup patterns depending on how much control you need.
Features
- Startup helpers:
Start,StartAsync,Build, and host shutdown helpers - Hook lifecycle:
IFrameworkHookscallbacks during host construction and startup - Async support: sync and async startup/shutdown variants
- Flexible startup: either framework-managed startup or direct host-builder configuration
Behavior
Start API
The simplest pattern is to let the framework create and run the host for you:
var options = new FrameworkOptions();
Application.Start<Hooks>(AppType.Web, options, AppHosting.Kestrel);
public class Hooks : IFrameworkHooks
{
public void OnConfigureServices(IServiceCollection services, EnvironmentType env)
{
}
}
This registers the framework services and middleware, builds the host, and blocks until shutdown.
Build API
Use the build helper when you want to configure the host builder before running it:
var options = new FrameworkOptions();
var urls = new[] { "http://localhost:5010" };
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. This is the pattern the repo uses in its current demo application:
var builder = Host.CreateDefaultBuilder(args);
builder.ConfigureFrameworkLogging();
builder.ConfigureServices((context, services) =>
{
services = services.AddFrameworkServices(AppType.Web, options);
});
builder = builder.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureFrameworkHosting();
webBuilder.Configure(app =>
{
app.UseFrameworkBeginMiddlewares(AppType.Web);
app.UseFrameworkEndMiddlewares(AppType.Web);
});
});
var app = builder.Build();
app.Run();
This approach gives the application full control over the host and pipeline while still using the framework's service registrations and middleware extensions.
Stopping the host
Application.HostStop();
// or
await Application.HostStopAsync();
Caveats
- Calling
StartorStartAsynctwice throwsInvalidOperationExceptionbecause only one host instance is allowed at a time. - The
IFrameworkHookslifecycle is skipped when the extension API is used directly. - For most applications, the HostBuilder +
AddFrameworkServicespattern is the clearest and most explicit option.
Tip
Use Application.Start when you want the framework to manage the host lifecycle. Use Application.Build when you need to configure the host before Run(). Use the extension API when you already have an ASP.NET host setup and want direct control over the pipeline.