CP.AspNetCore.SignalR.Client.Rx.Reactive 1.6.0

dotnet add package CP.AspNetCore.SignalR.Client.Rx.Reactive --version 1.6.0
                    
NuGet\Install-Package CP.AspNetCore.SignalR.Client.Rx.Reactive -Version 1.6.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="CP.AspNetCore.SignalR.Client.Rx.Reactive" Version="1.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CP.AspNetCore.SignalR.Client.Rx.Reactive" Version="1.6.0" />
                    
Directory.Packages.props
<PackageReference Include="CP.AspNetCore.SignalR.Client.Rx.Reactive" />
                    
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 CP.AspNetCore.SignalR.Client.Rx.Reactive --version 1.6.0
                    
#r "nuget: CP.AspNetCore.SignalR.Client.Rx.Reactive, 1.6.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 CP.AspNetCore.SignalR.Client.Rx.Reactive@1.6.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=CP.AspNetCore.SignalR.Client.Rx.Reactive&version=1.6.0
                    
Install as a Cake Addin
#tool nuget:?package=CP.AspNetCore.SignalR.Client.Rx.Reactive&version=1.6.0
                    
Install as a Cake Tool

CP.AspNetCore.SignalR.Client.Rx

ReactiveUI.Primitives extensions for Microsoft.AspNetCore.SignalR.Client.

Installation

Install-Package CP.AspNetCore.SignalR.Client.Rx

Use the lean package above when the application does not otherwise depend on System.Reactive. Applications that require System.Reactive interoperability can install the shared-source variant:

Install-Package CP.AspNetCore.SignalR.Client.Rx.Reactive

Overview

CP.AspNetCore.SignalR.Client.Rx provides high-performance, memory-efficient observable APIs for SignalR client applications. The lean package is based on ReactiveUI.Primitives; the .Reactive package uses ReactiveUI.Primitives.Reactive and the CP.AspNetCore.SignalR.Client.Rx.Reactive namespace.

  • Targets: .NET Framework 4.6.2, .NET 8, .NET 9, .NET 10, and .NET 11
  • Supports: WPF, WinForms, Console, ASP.NET Core, Razor Pages, and more

Quick Start

using CP.AspNetCore.SignalR.Client.Rx;
using Microsoft.AspNetCore.SignalR.Client;

var connection = new HubConnectionBuilder()
    .WithUrl("http://localhost:5000/hub")
    .WithAutomaticReconnect()
    .Build();

// Subscribe to a hub method
var sub = connection.On(new HubMethod<string>("Stream")).Subscribe(Console.WriteLine);

// Start the connection reactively
connection.StartObservable().Subscribe();

Advanced Usage

Using HubBuilder for Lifecycle Management

using CP.AspNetCore.SignalR.Client.Rx;

HubBuilder.Create(builder => builder.WithUrl("https://localhost:53933/ChatHub"))
    .Subscribe(x =>
    {
        var connection = x.hubConnection;
        var disposables = x.disposables;

        // Listen for messages
        disposables.Add(connection.On(new HubMethod<(string, string)>("ReceiveMessage"))
            .Subscribe(msg => Console.WriteLine($"{msg.t1}: {msg.t2}")));

        // Handle connection closed
        disposables.Add(connection.HasClosed().Subscribe(error =>
            Console.WriteLine($"Closed: {error?.Message}")));

        // Start the connection from any observable trigger.
        // disposables.Add(connectRequested.Start(connection).Subscribe());
    });

Streaming from the Server

connection.StreamObservable(new HubMethod<int>("Counter"), CancellationToken.None, 10)
    .Subscribe(
        value => Console.WriteLine($"Received: {value}"),
        ex => Console.WriteLine($"Error: {ex.Message}"),
        () => Console.WriteLine("Stream completed"));

Invoking Methods and Sending Data

// Invoke a method and get a result
connection.InvokeObservable(new HubMethod<int>("AddNumbers"), CancellationToken.None, 1, 2)
    .Subscribe(result => Console.WriteLine($"Sum: {result}"));

// Send a method (fire-and-forget)
connection.SendObservable("Notify", CancellationToken.None, "Hello!")
    .Subscribe(_ => Console.WriteLine("Notification sent"));

Observing Connection State

connection.StateChanges().Subscribe(state =>
    Console.WriteLine($"Connection state: {state}"));

// Wait for a specific state
connection.WaitForState(HubConnectionState.Connected)
    .Subscribe(_ => Console.WriteLine("Connected!"));

Razor Pages Example

@page
@using CP.AspNetCore.SignalR.Client.Rx
@inject Microsoft.AspNetCore.SignalR.Client.HubConnection Connection

@functions {
    protected override void OnInitialized()
    {
        Connection.On(new HubMethod<string>("ReceiveMessage"))
            .Subscribe(msg => /* update UI */);
        Connection.StartObservable().Subscribe();
    }
}

API Reference

Event Subscription

  • On(string methodName) — No-arg handler
  • On<T>(HubMethod<T> method)
  • On<T1, T2>(HubMethod<(T1, T2)> method)
  • ... up to 8 arguments

Connection Lifecycle

  • StartObservable() / StartObservable(CancellationToken)
  • StartObservable(int? retryCount, CancellationToken)
  • StopObservable() / StopObservable(CancellationToken)
  • StopObservable(int? retryCount, CancellationToken)
  • EnsureStarted() / EnsureStarted(CancellationToken)
  • StateChanges()
  • WaitForState(HubConnectionState)

Streaming

  • StreamObservable<T>(HubMethod<T> method, CancellationToken, params object?[] args)

Invocation

  • InvokeObservable<T>(HubMethod<T> method, CancellationToken, params object?[] args)
  • InvokeObservable(string methodName, CancellationToken, params object?[] args)
  • SendObservable(string methodName, CancellationToken, params object?[] args)

Connection Events

  • HasClosed()
  • IsReconnecting()
  • HasReconnected()

HubBuilder

  • HubBuilder.Create(Func<HubConnectionBuilder, IHubConnectionBuilder>)

Best Practices

  • Always dispose subscriptions to avoid memory leaks.
  • Use the disposable scope returned by HubBuilder.Create for managing multiple subscriptions.
  • Prefer StartObservable/StopObservable for connection management in Rx scenarios.
  • Use StreamObservable for server-to-client streaming.

License

MIT

See Also


CP.AspNetCore.SignalR.Client.Rx - Empowering Industrial Automation with Reactive Technology ⚡🏭

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 is compatible.  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 is compatible.  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.  net11.0 is compatible. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  net481 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.6.0 119 8/2/2026

Compatibility with .NET 8 / 9 / 10 / 11 and .NET Framework 4.6.2 / 4.7.2 / 4.8 / 4.8.1