Host Concept
In ASP.NET Core host documentation, a host is defined as: An object that encapsulates an app's resources and manages the app's lifetime.
.NET provides two host types:
- Generic Host: Manages service lifetime and dependency injection without an HTTP pipeline
- Web Host: Adds HTTP request handling and middleware pipeline configuration (exposes an HTTP port via
Startup)
In a Silky microservice cluster, two communication modes exist:
- Receive external HTTP requests → route via WebAPI to a service entry → execute via local or remote executor
- Service-to-service communication via DotNetty RPC over TCP
For mode 1, a Web Host is required (gateway or HTTP-capable business service).
For mode 2 (most business services), a General Host is sufficient — no HTTP pipeline is needed.
Registering a Silky Application
The minimal registration for a Silky microservice:
private static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureSilkyGeneralHostDefaults<AppModule>();
}
Internally, ConfigureSilkyGeneralHostDefaults<T>() calls RegisterSilkyServices<T>(), which:
- Creates the
SilkyFileProvider(used to scan assemblies and provide file helpers) - Creates the global singleton
SilkyEngineviaEngineContext.Create() - Registers core services:
SilkyFileProvider,ModuleLoader,NullCancellationTokenProvider - Resolves, loads, and topologically sorts all Silky modules starting from
T - Registers
InitSilkyHostedService(background service for module initialization and shutdown) - Calls
engine.ConfigureServices()— scansIConfigureServiceimplementations and calls each module'sConfigureServices()
WebAPI Call Example
Given the interface:
[ServiceRoute(template: "api/system/{appservice=silkyapp}")]
public interface ISystemAppService
{
[AllowAnonymous]
GetSystemInfoOutput GetInfo();
}
Silky infers HTTP GET from the GetInfo method name, strips the Get prefix, and generates:
GET /api/system/silkyapp/info
Full execution chain:
External HTTP client
│ GET /api/system/silkyapp/info
▼
Gateway / Web Host (HTTP port)
│ ASP.NET Core routing middleware matches ServiceEntry
▼
DefaultExecutor.Execute()
│ Is ISystemAppService implemented locally?
│ ├── Yes (Web Host with Application layer) → LocalExecutor → direct execution
│ └── No (Gateway mode) → RemoteExecutor → DotNetty RPC → business microservice
▼
GetSystemInfoOutput (serialized to JSON)
Host Types
| Host Type | Method | HTTP Port | RPC Port |
|---|---|---|---|
| General Host | ConfigureSilkyGeneralHostDefaults<T>() | ❌ | ✅ |
| Web Host | ConfigureSilkyWebHostDefaults<T>() | ✅ | ✅ |
| WebSocket Host | ConfigureSilkyWebSocketHostDefaults<T>() | ✅ | ✅ |
| Gateway Host | ConfigureSilkyGatewayDefaults<T>() | ✅ | ❌ |
