Linkduck 1.0.0

dotnet add package Linkduck --version 1.0.0
                    
NuGet\Install-Package Linkduck -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Linkduck" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linkduck" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Linkduck" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Linkduck --version 1.0.0
                    
#r "nuget: Linkduck, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Linkduck@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Linkduck&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Linkduck&version=1.0.0
                    
Install as a Cake Tool

Linkduck

CI NuGet Version License

Linkduck 是一个连接管理框架,提供统一的连接生命周期管理、状态事件和自动重连。

目前内置的传输层实现:SignalR。框架预留了扩展点,可自行实现 WebSocket、MQTT 等其他协议。

Packages

Package NuGet Description
Linkduck.Abstractions NuGet Interfaces, base classes, and enums for building custom connection types
Linkduck NuGet Core implementation: Manager, InMemoryStore, HostService, DI integration
Linkduck.SignalR NuGet SignalR transport — client-side and server-side

Quick Start — SignalR

dotnet add package Linkduck.SignalR

Client Side(主动连接)

需要自行继承的类:

基类 用途
SignalRLinkduckBase 连接实例,在 ConfigureHubAsync 中注册消息处理器
LinkduckFactoryBase 工厂,根据 LinkduckInfo 创建连接实例
ISignalRTokenProvider Token 提供者(可选,仅需认证时实现)
public class MyConnection : SignalRLinkduckBase
{
    public MyConnection(string name, string type, SignalRLinkduckOptions opts, IServiceProvider sp)
        : base(name, type, LinkduckMode.Active, opts, sp) { }

    protected override async Task ConfigureHubAsync(HubConnection hub)
    {
        // 注册消息处理器,断线重连后自动重新注册
        hub.On<string>("ReceiveHello", message =>
        {
            Console.WriteLine($"收到: {message}");
        });
    }
}

public class MyFactory : LinkduckFactoryBase
{
    readonly IServiceProvider _sp;
    public MyFactory(string type, IServiceProvider sp) : base(type) => _sp = sp;
    public override ILinkduck Create(LinkduckInfo info)
    {
        var opts = new SignalRLinkduckOptions { HubUri = new Uri(info.Options["HubUri"]) };
        return new MyConnection(info.Name, info.Type, opts, _sp);
    }
}

// 注册到 DI(种子配置 → 自动创建连接 → 自动重连)
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddInMemoryLinkduckStore(new[]
{
    new LinkduckInfo
    {
        Name = "client1", Type = "myType",
        Options = new() { { "HubUri", "http://localhost:5000/hub" }, { "UseToken", "true" } }
    }
});
builder.Services.AddLinkduckFactory<MyFactory>("myType");
builder.Services.AddSignalRTokenProvider<MyTokenProvider>("myType");
await builder.Build().RunAsync();

Server Side(被动监听)

需要自行继承的类:

基类 用途
SignalRLinkduckHubBase<TListener> Hub,定义服务端方法供客户端调用
SignalRLinkduckListenerBase 监听器,处理客户端连接/断开事件
public class MyHub : SignalRLinkduckHubBase<MyListener>
{
    public MyHub(MyListener listener) : base(listener) { }

    // 客户端可通过 connection.InvokeAsync("SayHello", "world") 调用
    public Task<string> SayHello(string name)
        => Task.FromResult($"Hello, {name}!");
}

public class MyListener : SignalRLinkduckListenerBase
{
    public MyListener(string type) : base(type) { }
    protected override Task OnStartingAsync(CancellationToken ct) => Task.CompletedTask;
    protected override Task OnStoppingAsync(CancellationToken ct) => Task.CompletedTask;
}

// 注册到 DI
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSignalRListenerWithHub<MyListener, MyHub>("myType", "/hub");

var app = builder.Build();
app.UseLinkduckSignalR();
await app.RunAsync();

自动重连:客户端连接断开后,SignalR 内置自动重连 + LinkduckBase 后台重试循环双重保障。服务端 Hub 方法定义不变,客户端 .On() 注册的处理器在重连后自动恢复。

See docs/guide.md for detailed usage and docs/design.md for architecture.

License

MIT License — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Linkduck:

Package Downloads
Linkduck.SignalR

SignalR integration for the Linkduck connection management framework. Provides SignalR-specific ILinkduck and ILinkduckListener implementations, hub base classes, token provider abstraction, and endpoint routing extensions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 135 7/27/2026