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

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

AdvantageDescription
Interface as ServiceInterfaces annotated with [ServiceRoute] automatically generate HTTP WebAPI and RPC endpoints — no Controller required
Transparent Local CallInject any service interface via DI; Silky generates a dynamic proxy at runtime that hides all RPC details
Multiple Host TypesWeb Host (HTTP), General Host (RPC only), WebSocket Host, Gateway Host
Multiple RegistriesBuilt-in Zookeeper, Nacos, Consul support — switch by changing one config line
Built-in GovernancePlug-and-play load balancing, circuit breaking, retry, rate limiting, fallback — powered by Polly
TCC Distributed TransactionFramework-level TCC support via interceptor + Redis journal for cross-service consistency
Deep .NET IntegrationFully compatible with ASP.NET Core middleware, DI, configuration system, and logging (Serilog)

Prerequisites

  1. (Required) Install .NET 6 SDK or higher (.NET 6 / 7 / 8 / 9 / 10 supported).
  2. (Required) Visual Studio 2022+ or JetBrains Rider as the IDE.
  3. (Required) A running service registry: Zookeeper, Nacos, or Consul (choose one).
  4. (Required) A Redis instance 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 TypePackage
General Host (RPC only)Silky.Agent.Host
Web HostSilky.Agent.Host
GatewaySilky.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();
    });
}

Next Steps

  • App Services & Service Entries
  • RPC Communication
  • Service Governance
  • Distributed Transactions
  • Caching Interception
Edit this page
Prev
Glossary
Next
Project Template