Nesco.SignalRCommunicator.Core
1.0.1
dotnet add package Nesco.SignalRCommunicator.Core --version 1.0.1
NuGet\Install-Package Nesco.SignalRCommunicator.Core -Version 1.0.1
<PackageReference Include="Nesco.SignalRCommunicator.Core" Version="1.0.1" />
<PackageVersion Include="Nesco.SignalRCommunicator.Core" Version="1.0.1" />
<PackageReference Include="Nesco.SignalRCommunicator.Core" />
paket add Nesco.SignalRCommunicator.Core --version 1.0.1
#r "nuget: Nesco.SignalRCommunicator.Core, 1.0.1"
#:package Nesco.SignalRCommunicator.Core@1.0.1
#addin nuget:?package=Nesco.SignalRCommunicator.Core&version=1.0.1
#tool nuget:?package=Nesco.SignalRCommunicator.Core&version=1.0.1
Nesco.SignalRCommunicator.Core
Core library for SignalR-based client-server communication with support for large data transfer via file uploads.
Overview
This package contains the shared models, interfaces, and configuration options used by both the client and server packages.
Installation
dotnet add package Nesco.SignalRCommunicator.Core
What's Included
Models
SignalRResponse: Standardized response object for method invocations- Supports multiple response types: JsonObject, FilePath, Null, Error
- Handles both direct data transmission and file-based transfers for large data
SignalRResponseType: Enum defining response types
Interfaces
IMethodExecutor: Contract for executing methods on the client side- Implement this interface to route method calls to your business logic
IFileUploadService: Contract for uploading large response data- Implement for custom storage solutions (cloud, network shares, etc.)
IFileReaderService: Contract for reading uploaded files on the server- Implement for custom file retrieval logic
Options
SignalRClientOptions: Configuration for client behavior- Server URL and hub path
- Timeouts and retry logic
- Maximum direct data size threshold
SignalRServerOptions: Configuration for server behavior- Maximum concurrent requests
- Request timeout
- Automatic file cleanup
Response Types Explained
JsonObject
Used when the response data is small enough to be sent directly through SignalR (default: ≤10KB).
var response = new SignalRResponse
{
ResponseType = SignalRResponseType.JsonObject,
JsonData = myDataObject
};
FilePath
Used when the response data exceeds the size threshold. Data is uploaded to a file, and the path is returned.
var response = new SignalRResponse
{
ResponseType = SignalRResponseType.FilePath,
FilePath = "/uploads/temp/result_abc123.json"
};
Null
Used when a method returns null or no data.
var response = new SignalRResponse
{
ResponseType = SignalRResponseType.Null
};
Error
Used when an error occurs during method execution.
var response = new SignalRResponse
{
ResponseType = SignalRResponseType.Error,
ErrorMessage = "Failed to process request: Database connection timeout"
};
Implementing IMethodExecutor
The method executor is responsible for routing method calls to your business logic:
public class MyMethodExecutor : IMethodExecutor
{
private readonly IMyService _myService;
public MyMethodExecutor(IMyService myService)
{
_myService = myService;
}
public async Task<object?> ExecuteAsync(string methodName, object? parameter)
{
return methodName switch
{
"GetUserData" => await _myService.GetUserData(ConvertParameter<int>(parameter)),
"UpdateSettings" => await _myService.UpdateSettings(ConvertParameter<SettingsDto>(parameter)),
"ProcessOrder" => await _myService.ProcessOrder(ConvertParameter<OrderDto>(parameter)),
_ => throw new NotSupportedException($"Method '{methodName}' is not supported")
};
}
private T ConvertParameter<T>(object? parameter)
{
if (parameter is JsonElement jsonElement)
{
return JsonSerializer.Deserialize<T>(jsonElement.GetRawText())!;
}
if (parameter is T directCast)
{
return directCast;
}
var json = JsonSerializer.Serialize(parameter);
return JsonSerializer.Deserialize<T>(json)!;
}
}
Thread Safety
All models and options are designed to be thread-safe when used as intended. The response handling mechanism uses concurrent collections to manage multiple simultaneous requests.
License
MIT License - see LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Nesco.SignalRCommunicator.Core:
| Package | Downloads |
|---|---|
|
Nesco.SignalRCommunicator.Client
Client library for SignalR-based communication. Connect to a SignalR server, receive method invocations, and return responses with automatic large data handling. |
|
|
Nesco.SignalRCommunicator.Server
Server library for SignalR-based communication. Invoke methods on connected clients and receive responses with automatic large data handling. |
GitHub repositories
This package is not used by any popular GitHub repositories.