Hosting Model¶
The Nalix Hosting Model is a high-level abstraction designed to feel familiar to .NET developers. It provides a builder/build/run workflow around packet registration, dispatch configuration, and listener binding.
NetworkApplication¶
At the heart of the hosting model is the NetworkApplication. It is the entry point that orchestrates the lifetime of the server, managing listeners, DI containers, and the middleware pipeline.
The Builder Pattern¶
You configure your application using the NetworkApplicationBuilder. This allows for a fluent, easy-to-read setup process:
using Nalix.Hosting;
using Nalix.Hosting;
using Nalix.Network.Options;
var builder = NetworkApplication.CreateBuilder();
builder.ConfigureCertificate("path/to/certificate.private")
.Configure<NetworkSocketOptions>(options => options.Port = 8080)
.ScanPackets<MyPacket>()
.ScanHandlers<MyHandlers>()
.BindTcp<MyProtocol>()
.Bind();
var app = builder.Build();
await app.RunAsync();
Application Lifecycle¶
The hosting model manages the four major stages of a server's life:
- Bootstrap: Loading configuration, registering logger / pools / packet registry, and initializing handshake identity.
- Startup: Creating the packet dispatcher, opening TCP or UDP listeners, and activating hosted services.
- Runtime: Accepting connections, dispatching packets, and managing session state.
- Shutdown: Stopping listeners and disposing runtime resources through
NetworkApplication.
Why use the Hosting Model?¶
While you can use the low-level Nalix.Network APIs directly, the Hosting model provides several built-in advantages:
- Fluent Setup: Listener binding, packet discovery, and dispatch configuration live in one builder.
- Configuration: Strongly-typed options are applied through
Configure<TOptions>(...). - Explicit Registration: Handlers can be discovered with
ScanHandlers<TMarker>()or registered directly withAddHandler<THandler>(). - Logging: Integrated logging via
ILoggerabstractions.