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
| Method | Called When | Usage |
|---|---|---|
PreConfigureServices(context) | Before ConfigureServices | Register services needed by other modules |
ConfigureServices(context) | ConfigureServices phase | Main registration and Options configuration |
PostConfigureServices(context) | After ConfigureServices | Finalize configuration |
PreInitialize(context) | Before Initialize | Pre-initialization setup |
Initialize(context) | Initialize phase | Activate middleware, background services |
PostInitialize(context) | After Initialize | Post-initialization tasks |
Shutdown(context) | Application shutdown | Cleanup, 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 Class | NuGet Package | Function |
|---|---|---|
DotNettyTcpModule | Silky.DotNetty.Protocol.Tcp | DotNetty TCP RPC transport |
ZookeeperModule | Silky.RegistryCenter.Zookeeper | Zookeeper service registry |
NacosModule | Silky.RegistryCenter.Nacos | Nacos service registry |
ConsulModule | Silky.RegistryCenter.Consul | Consul service registry |
RpcProxyModule | Silky.Rpc.Proxy | Dynamic RPC proxy generation |
CachingModule | Silky.Caching | Distributed cache abstractions |
StackExchangeRedisCachingModule | Silky.Caching.StackExchangeRedis | Redis cache provider |
FluentValidationModule | Silky.Validation.Fluent | FluentValidation integration |
AutoMapperModule | Silky.ObjectMapper.AutoMapper | AutoMapper integration |
JwtModule | Silky.Jwt | JWT generation and validation |
TccTransactionModule | Silky.Transaction.Tcc | TCC distributed transactions |
SkyApmModule | Silky.SkyApm.Agent | SkyAPM distributed tracing |
Dependency Injection Conventions
Silky automatically scans and registers types implementing well-known DI marker interfaces:
| Interface | Lifetime | Notes |
|---|---|---|
ISingletonDependency | Singleton | One instance per application |
IScopedDependency | Scoped | One instance per RPC request |
ITransientDependency | Transient | New instance per resolution |
No manual registration is needed — just implement the appropriate marker interface.
