FluentSignals.SignalBus
2.1.0
See the version list below for details.
dotnet add package FluentSignals.SignalBus --version 2.1.0
NuGet\Install-Package FluentSignals.SignalBus -Version 2.1.0
<PackageReference Include="FluentSignals.SignalBus" Version="2.1.0" />
<PackageVersion Include="FluentSignals.SignalBus" Version="2.1.0" />
<PackageReference Include="FluentSignals.SignalBus" />
paket add FluentSignals.SignalBus --version 2.1.0
#r "nuget: FluentSignals.SignalBus, 2.1.0"
#:package FluentSignals.SignalBus@2.1.0
#addin nuget:?package=FluentSignals.SignalBus&version=2.1.0
#tool nuget:?package=FluentSignals.SignalBus&version=2.1.0
FluentSignals SignalBus
The SignalBus is a messaging system built on top of FluentSignals that provides a publish-subscribe pattern for communication between components in Blazor applications.
Features
- Type-safe messaging: Strongly-typed message publishing and consumption
- Async support: Both synchronous and asynchronous message handlers
- Scoped subscriptions: Automatic cleanup with component lifecycle
- Built on FluentSignals: Leverages the reactive signal system internally
Installation
Add the SignalBus services to your Blazor application:
// In Program.cs
builder.Services.AddFluentSignalsBlazorWithSignalBus();
// Register consumers for specific message types
builder.Services.AddSignalConsumer<MyMessage>();
Usage
Define Message Types
public class UserNotification
{
public string Message { get; set; }
public DateTime Timestamp { get; set; }
}
Publishing Messages
@inject ISignalPublisher Publisher
@code {
private void SendNotification()
{
var notification = new UserNotification
{
Message = "Hello from SignalBus!",
Timestamp = DateTime.Now
};
Publisher.Publish(notification);
}
}
Consuming Messages
@inject ISignalConsumer<UserNotification> NotificationConsumer
@implements IDisposable
@code {
private ISignalSubscriptionContract? _subscription;
protected override void OnInitialized()
{
_subscription = NotificationConsumer.Subscribe(notification =>
{
// Handle notification
Console.WriteLine($"Received: {notification.Message}");
StateHasChanged();
});
}
public void Dispose()
{
_subscription?.Dispose();
}
}
Async Message Handling
_subscription = NotificationConsumer.Subscribe(async notification =>
{
await ProcessNotificationAsync(notification);
StateHasChanged();
});
Advanced Usage
Using the Factory
@inject SignalConsumerFactory ConsumerFactory
@code {
private ISignalConsumer<MyMessage> _consumer;
protected override void OnInitialized()
{
_consumer = ConsumerFactory.CreateConsumer<MyMessage>();
// Subscribe to messages...
}
}
Direct Signal Access
For advanced scenarios, you can access the underlying signal:
var signal = consumer.Signal;
// Use signal directly for complex reactive patterns
Architecture
The SignalBus consists of:
- ISignalPublisher: Interface for publishing messages
- ISignalConsumer<T>: Interface for consuming typed messages
- SignalBus: Internal implementation managing signal routing
- SignalPublisher: Implementation of ISignalPublisher
- SignalConsumer<T>: Implementation wrapping typed signals
All message routing is handled through FluentSignals' TypedSignal<T> instances, providing reactive updates when messages are published.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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. |
-
net9.0
- FluentSignals (>= 2.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FluentSignals.SignalBus:
Package | Downloads |
---|---|
FluentSignals.Blazor
Blazor integration for FluentSignals - A reactive state management library. Includes SignalBus for component communication, HTTP resource components, typed resource factories, and Blazor-specific helpers. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release of FluentSignals.SignalBus - Event bus functionality extracted from FluentSignals.Blazor.