Chapter.Mediation
1.5.0
Suggested Alternatives
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Chapter.Mediation --version 1.5.0
NuGet\Install-Package Chapter.Mediation -Version 1.5.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="Chapter.Mediation" Version="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chapter.Mediation --version 1.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Chapter.Mediation, 1.5.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.
// Install Chapter.Mediation as a Cake Addin #addin nuget:?package=Chapter.Mediation&version=1.5.0 // Install Chapter.Mediation as a Cake Tool #tool nuget:?package=Chapter.Mediation&version=1.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Chapter.Mediation Library
Overview
Chapter.Mediation provides an implementation of the mediator pattern in the form of a sync and async message bus.
Features
- Sync Communication: Send an object to a list of receivers synchronously.
- Async Communication: Send an object to a list of receivers asynchronously.
- Custom Scheduler: Possibility to tunnel all message bus objects over and own scheduler.
Getting Started
Installation:
- Install the Chapter.Mediation library via NuGet Package Manager:
dotnet add package Chapter.Mediation
Send and receive a message synchronously:
- Sending:
public class SenderViewModel { private readonly IMessageBus _messageBus; public SenderViewModel(IMessageBus messageBus) { _messageBus = messageBus; } private void Publish() { _messageBus.Publish(new Notification()); } }
- Receiving:
public class ReceiverViewModel { private readonly IMessageBus _messageBus; private ISubscriber _token; public SubscriptionHelper(IMessageBus messageBus) { _messageBus = messageBus; _token = _messageBus.Subscribe<Notification>(Callback); } private void Callback(Notification param) { } }
Send and receive a message asynchronously:
- Sending:
public class AsyncSenderViewModel : ObservableObject { private readonly IMessageBus _messageBus; public AsyncSenderViewModel(IMessageBus messageBus) { _messageBus = messageBus; } private async Task Publish() { await _messageBus.PublishAsync(new Notification()); } }
- Receiving:
public class AsyncSubscriptionHelper<T> : ObservableObject { private readonly IMessageBus _messageBus; private IAsyncSubscriber _token; public AsyncSubscriptionHelper(IMessageBus messageBus) { _messageBus = messageBus; _messageBus.Subscribe<Notification>(Callback); } private async Task Callback(Notification param) { } }
Example
- Send and receive a message synchronously using a custom scheduler.
public class DispatcherScheduler : IScheduler { public DispatcherScheduler(Dispatcher dispatcher) { _dispatcher = dispatcher; } public void Invoke(Action action) { _dispatcher.Invoke(action); } }
public class SenderViewModel { private readonly IMessageBus _messageBus; public SenderViewModel(IMessageBus messageBus) { _messageBus = messageBus; PublishCommand = new DelegateCommand(Publish); } public IDelegateCommand PublishCommand; private void Publish() { _messageBus.Publish(new Notification()); } }
public class ReceiverViewModel { private readonly IMessageBus _messageBus; private ISubscriber _token; public SubscriptionHelper(IMessageBus messageBus) { _messageBus = messageBus; _scheduler = new DispatcherScheduler(Dispatcher.CurrentDispatcher); _token = _messageBus.Subscribe<Notification>(Callback).On(_scheduler); } private void Callback(Notification param) { } }
Links
License
Copyright (c) David Wendland. All rights reserved.
Licensed under the MIT License. See LICENSE file in the project root for full license information.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- No dependencies.
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 |
---|