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

    • Silky Framework Overview
  • Getting Started

    • Glossary
    • Quick Start
    • Project Template
    • Microservice Architecture
    • Sample Projects
  • Host & Module

    • Host Types
    • Gateway Configuration
    • Module System
    • Plugin System
  • Gateway & HTTP

    • Swagger / OpenAPI
    • MiniProfiler
    • CORS
    • Audit Logging
  • Service & RPC

    • App Services & Service Entries
    • RPC Communication
    • WebSocket
    • Service Registry
    • Service Governance
  • Data & Cache

    • EFCore Data Access
    • Caching
    • Distributed Lock
  • Security & Auth

    • Identity & Authentication
    • Distributed Transactions
  • Infrastructure

    • Dependency Injection
    • Object Mapping
    • Validation
    • Link Tracking (SkyAPM)
    • Logging (Serilog)
    • Health Checks
    • Message Bus (MassTransit)
    • Unit & Integration Testing

Overview

Silky's extensibility is built around a module system. A module encapsulates a cohesive set of services, middleware, and configuration. The framework discovers and initializes all modules in dependency order at startup.

Defining a Module

Inherit from SilkyModule and decorate with [DependsOn] to declare module dependencies:

using Silky.Core.Modularity;

[DependsOn(
    typeof(DotNettyTcpModule),
    typeof(ZookeeperModule),
    typeof(RpcModule),
    typeof(FluentValidationModule)
)]
public class OrderHostModule : SilkyModule
{
    // Override lifecycle hooks as needed
}

Module Lifecycle Hooks

MethodCalled WhenUsage
PreConfigureServices(context)Before ConfigureServicesRegister services needed by other modules
ConfigureServices(context)ConfigureServices phaseMain registration and Options configuration
PostConfigureServices(context)After ConfigureServicesFinalize configuration
PreInitialize(context)Before InitializePre-initialization setup
Initialize(context)Initialize phaseActivate middleware, background services
PostInitialize(context)After InitializePost-initialization tasks
Shutdown(context)Application shutdownCleanup, resource disposal

Registration Example

[DependsOn(typeof(EntityFrameworkCoreModule))]
public class OrderDomainModule : SilkyModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddDbContext<OrderDbContext>(opts =>
            opts.UseNpgsql(context.Services
                .GetConfiguration()
                .GetConnectionString("Default")));

        context.Services.Configure<OrderSettings>(
            context.Services.GetConfiguration().GetSection("Order"));
    }
}

Module Initialization Order

The framework computes a topological sort over all [DependsOn] declarations and initializes modules in that order:

InfrastructureModule → DomainModule → ApplicationModule → HostModule

Pre-Built Framework Modules

Module ClassNuGet PackageFunction
DotNettyTcpModuleSilky.DotNetty.Protocol.TcpDotNetty TCP RPC transport
ZookeeperModuleSilky.RegistryCenter.ZookeeperZookeeper service registry
NacosModuleSilky.RegistryCenter.NacosNacos service registry
ConsulModuleSilky.RegistryCenter.ConsulConsul service registry
RpcProxyModuleSilky.Rpc.ProxyDynamic RPC proxy generation
CachingModuleSilky.CachingDistributed cache abstractions
StackExchangeRedisCachingModuleSilky.Caching.StackExchangeRedisRedis cache provider
FluentValidationModuleSilky.Validation.FluentFluentValidation integration
AutoMapperModuleSilky.ObjectMapper.AutoMapperAutoMapper integration
JwtModuleSilky.JwtJWT generation and validation
TccTransactionModuleSilky.Transaction.TccTCC distributed transactions
SkyApmModuleSilky.SkyApm.AgentSkyAPM distributed tracing

Dependency Injection Conventions

Silky automatically scans and registers types implementing well-known DI marker interfaces:

InterfaceLifetimeNotes
ISingletonDependencySingletonOne instance per application
IScopedDependencyScopedOne instance per RPC request
ITransientDependencyTransientNew instance per resolution

No manual registration is needed — just implement the appropriate marker interface.

Edit this page
Prev
Gateway Configuration
Next
Plugin System