Silky Microservice FrameworkSilky Microservice Framework
Home
Docs
Config
Source
github
gitee
  • 简体中文
  • English
Home
Docs
Config
Source
github
gitee
  • 简体中文
  • English
  • Startup

    • Silky Framework Source Code Analysis
    • Host Construction
    • Service Engine
    • Module System
    • Service & Service Entry Resolution
    • Service Registration
    • Dependency Injection Conventions
    • RPC Service Proxy
  • Runtime

    • Endpoints & Routing
    • Executor Dispatch System
    • Local Executor & Server-Side Filters
    • Remote Executor & RPC Call Chain
    • RPC Server Message Handling
    • Service Governance
    • Cache Interceptor
    • Distributed Transactions (TCC)
    • HTTP Gateway Pipeline
    • Filter Pipeline
    • Polly Resilience Pipeline
    • Endpoint Health Monitor

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:

  1. Receive external HTTP requests → route via WebAPI to a service entry → execute via local or remote executor
  2. 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:

  1. Creates the SilkyFileProvider (used to scan assemblies and provide file helpers)
  2. Creates the global singleton SilkyEngine via EngineContext.Create()
  3. Registers core services: SilkyFileProvider, ModuleLoader, NullCancellationTokenProvider
  4. Resolves, loads, and topologically sorts all Silky modules starting from T
  5. Registers InitSilkyHostedService (background service for module initialization and shutdown)
  6. Calls engine.ConfigureServices() — scans IConfigureService implementations and calls each module's ConfigureServices()

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 TypeMethodHTTP PortRPC Port
General HostConfigureSilkyGeneralHostDefaults<T>()❌✅
Web HostConfigureSilkyWebHostDefaults<T>()✅✅
WebSocket HostConfigureSilkyWebSocketHostDefaults<T>()✅✅
Gateway HostConfigureSilkyGatewayDefaults<T>()✅❌
Edit this page
Prev
Silky Framework Source Code Analysis
Next
Service Engine