What is Silky?
Silky is a microservice development framework built on the .NET platform, focused on RPC communication and microservice governance. It follows the mainstream .NET programming model and allows developers to transform a plain .NET host application into a microservice — with service registration, discovery, remote invocation, and distributed transactions — with minimal code.
Core Advantages
| Advantage | Description |
|---|---|
| Interface as Service | Interfaces annotated with [ServiceRoute] automatically generate HTTP WebAPI and RPC endpoints — no Controller required |
| Transparent Local Call | Inject any service interface via DI; Silky generates a dynamic proxy at runtime that hides all RPC details |
| Multiple Host Types | Web Host (HTTP), General Host (RPC only), WebSocket Host, Gateway Host |
| Multiple Registries | Built-in Zookeeper, Nacos, Consul support — switch by changing one config line |
| Built-in Governance | Plug-and-play load balancing, circuit breaking, retry, rate limiting, fallback — powered by Polly |
| TCC Distributed Transaction | Framework-level TCC support via interceptor + Redis journal for cross-service consistency |
| Deep .NET Integration | Fully compatible with ASP.NET Core middleware, DI, configuration system, and logging (Serilog) |
Prerequisites
- (Required) Install .NET 6 SDK or higher (.NET 6 / 7 / 8 / 9 / 10 supported).
- (Required) Visual Studio 2022+ or JetBrains Rider as the IDE.
- (Required) A running service registry:
Zookeeper,Nacos, orConsul(choose one). - (Required) A
Redisinstance for distributed caching.
Quick Init with Project Templates (Recommended)
Silky provides the official silky.app project template to skip manual setup and generate a standard project structure in one command:
# Install the template
dotnet new install Silky.App.Template
# Create a gateway
dotnet new silky.app -t gateway -n Silky.Gateway
# Create a General Host microservice
dotnet new silky.app -t generalhost -n Silky.Demo
# Create a Web Host microservice
dotnet new silky.app -t webhost -n Silky.Demo
To set up manually, continue reading below.
Building a Microservice with a Web Host
Use the .NET Web Host to build a Silky microservice.
Step 1: Install Packages
PM> Install-Package Silky.Agent.Host
Or choose the appropriate host package:
| Host Type | Package |
|---|---|
| General Host (RPC only) | Silky.Agent.Host |
| Web Host | Silky.Agent.Host |
| Gateway | Silky.Http.Core + registry package |
Step 2: Configure the Host
// Program.cs
var hostBuilder = Host.CreateDefaultBuilder(args)
.ConfigureSilkyWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
await hostBuilder.Build().RunAsync();
Step 3: Add Configuration
# appsettings.yml
rpc:
token: "your-rpc-token" # Shared secret across the cluster
registrycenter:
type: Zookeeper
connectionStrings: "127.0.0.1:2181"
redis:
configuration: "127.0.0.1:6379"
Step 4: Define a Service Interface
Create a class library project for the service interface (to be referenced by other services):
// IGreetingAppService.cs
using Silky.Rpc.Routing;
[ServiceRoute]
public interface IGreetingAppService
{
Task<string> SayHelloAsync(string name);
}
Step 5: Implement the Service
// GreetingAppService.cs
using Silky.Core.DependencyInjection;
public class GreetingAppService : IGreetingAppService, IScopedDependency
{
public Task<string> SayHelloAsync(string name)
{
return Task.FromResult($"Hello, {name}!");
}
}
Step 6: Call Another Service via RPC
Inject the interface of another microservice and call it just like a local method:
public class OrderAppService : IOrderAppService, IScopedDependency
{
private readonly IGreetingAppService _greetingService;
public OrderAppService(IGreetingAppService greetingService)
{
_greetingService = greetingService;
}
public async Task<string> CreateOrderAsync(string customerName)
{
// Silky routes this to the remote GreetingAppService automatically
var greeting = await _greetingService.SayHelloAsync(customerName);
return $"Order created. {greeting}";
}
}
Building a Gateway
The gateway is responsible for routing external HTTP requests to internal microservices.
Step 1: Install Packages
PM> Install-Package Silky.Agent.Host
PM> Install-Package Silky.Http.Core
PM> Install-Package Silky.Http.Swagger # optional: Swagger UI
PM> Install-Package Silky.Jwt # optional: JWT authentication
Step 2: Configure the Gateway Host
var hostBuilder = Host.CreateDefaultBuilder(args)
.ConfigureSilkyGatewayDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
await hostBuilder.Build().RunAsync();
Step 3: Enable Swagger (Optional)
// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddSilkyHttpCore()
.AddSwaggerDocuments(); // aggregate swagger from all microservices
}
public void Configure(IApplicationBuilder app)
{
app.UseSilkyRpcHealthCheck();
app.UseSwaggerDocuments(); // serve Swagger UI
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapSilkyRpcServices();
});
}
