CCSWE.nanoFramework.Mediator
1.0.19
dotnet add package CCSWE.nanoFramework.Mediator --version 1.0.19
NuGet\Install-Package CCSWE.nanoFramework.Mediator -Version 1.0.19
<PackageReference Include="CCSWE.nanoFramework.Mediator" Version="1.0.19" />
paket add CCSWE.nanoFramework.Mediator --version 1.0.19
#r "nuget: CCSWE.nanoFramework.Mediator, 1.0.19"
// Install CCSWE.nanoFramework.Mediator as a Cake Addin
#addin nuget:?package=CCSWE.nanoFramework.Mediator&version=1.0.19
// Install CCSWE.nanoFramework.Mediator as a Cake Tool
#tool nuget:?package=CCSWE.nanoFramework.Mediator&version=1.0.19
CCSWE.nanoFramework.Mediator
A simple asynchronous mediator implementation for nanoFramework. Provides in-process publisher-subscriber communication while keeping all parties decoupled.
Based on Mako-IoT.Device.Services.Mediator
Usage
Create classes for your events
public class Event1 : IMediatorEvent
{
public string Data { get; set; }
}
public class Event2 : IMediatorEvent
{
public string Text { get; set; }
}
Your event subscriber must implement IMediatorEventHandler
interface
public class EventHandlerService : IMediatorEventHandler
{
public void HandleEvent(IMediatorEvent mediatorEvent)
{
switch (mediatorEvent)
{
case Event1 event1:
Debug.WriteLine($"[{nameof(EventHandlerService)}] Event1 received. The data is: {event1.Data}");
break;
case Event2 event2:
Debug.WriteLine($"[{nameof(EventHandlerService)}] Event2 received The text is: {event2.Text}");
break;
}
}
}
Use IMediator
to publish events
public class EventPublisherService : IEventPublisherService
{
private readonly IMediator _mediator;
public EventPublisherService(IMediator mediator)
{
_mediator = mediator;
}
public void DoSomething()
{
_mediator.Publish(new Event2 { Text = "Hello from EventPublisherService" });
}
}
Register AsyncMediator
and singleton subscribers to an IHostBuilder
...
var hostBuilder = new HostBuilder();
hostBuilder.UseMediator(options =>
{
options.AddSubscriber(typeof(Event1), typeof(Service2));
options.AddSubscriber(typeof(Event2), typeof(Service2));
});
... or directly to an IServiceCollection
var serviceCollection = new ServiceCollection();
serviceCollection.AddMediator(options =>
{
options.AddSubscriber(typeof(Event1), typeof(Service2));
options.AddSubscriber(typeof(Event2), typeof(Service2));
});
For transient and scoped services you can use the Subscribe
and Unsubscribe
overloads that take a specific instance.
public class TransientService : IDisposable
{
private readonly IMediator _mediator;
public TransientService(IMediator mediator)
{
_mediator = mediator;
_mediator.Subscribe(typeof(Event1), this);
_mediator.Subscribe(typeof(Event2), this);
}
public void Dispose()
{
_mediator.Unsubscribe(typeof(Event1), this);
_mediator.Unsubscribe(typeof(Event2), this);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
- CCSWE.nanoFramework.Collections.Concurrent (>= 1.0.12)
- CCSWE.nanoFramework.Core (>= 1.0.13)
- CCSWE.nanoFramework.Threading (>= 1.0.18)
- nanoFramework.CoreLibrary (>= 1.15.5)
- nanoFramework.DependencyInjection (>= 1.1.3)
- nanoFramework.Logging (>= 1.1.100)
- nanoFramework.System.Collections (>= 1.5.31)
- nanoFramework.System.Threading (>= 1.1.32)
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.0.19 | 0 | 5/21/2024 |
1.0.18 | 27 | 5/20/2024 |
1.0.17 | 40 | 5/19/2024 |
1.0.16 | 35 | 5/19/2024 |
1.0.15 | 43 | 5/19/2024 |
1.0.14 | 40 | 5/18/2024 |
1.0.12 | 42 | 5/16/2024 |
1.0.11 | 52 | 5/15/2024 |
1.0.10 | 53 | 5/13/2024 |
1.0.9 | 58 | 5/11/2024 |
1.0.8 | 60 | 5/10/2024 |
1.0.7 | 80 | 4/27/2024 |
1.0.6 | 85 | 4/26/2024 |
1.0.5 | 85 | 4/25/2024 |
1.0.4 | 77 | 4/25/2024 |
1.0.3 | 82 | 4/23/2024 |
1.0.2 | 83 | 4/20/2024 |
1.0.1 | 83 | 4/19/2024 |
1.0.0 | 84 | 4/19/2024 |
0.3.31 | 75 | 4/17/2024 |
0.3.30 | 97 | 4/13/2024 |
0.3.29 | 69 | 4/12/2024 |
0.3.28 | 81 | 4/11/2024 |
0.3.27 | 77 | 4/10/2024 |
0.3.26 | 77 | 4/9/2024 |
0.3.25 | 81 | 4/8/2024 |
0.3.24 | 66 | 4/7/2024 |
0.3.23 | 93 | 4/6/2024 |
0.3.22 | 79 | 4/5/2024 |
0.3.21 | 79 | 4/4/2024 |
0.3.20 | 83 | 4/3/2024 |
0.3.19 | 86 | 3/24/2024 |
0.3.18 | 94 | 3/22/2024 |
0.3.17 | 75 | 3/21/2024 |
0.3.16 | 100 | 2/6/2024 |
0.3.15 | 84 | 2/3/2024 |
0.3.14 | 79 | 2/1/2024 |
0.3.13 | 81 | 1/27/2024 |
0.3.12 | 76 | 1/26/2024 |
0.3.11 | 215 | 11/23/2023 |
0.3.10 | 106 | 11/22/2023 |
0.3.9 | 110 | 11/21/2023 |
0.3.8 | 119 | 11/17/2023 |
0.3.7 | 119 | 11/14/2023 |
0.3.6 | 100 | 11/13/2023 |
0.3.5 | 109 | 11/12/2023 |
0.3.4 | 107 | 11/12/2023 |
0.3.3 | 96 | 11/12/2023 |
0.3.2 | 95 | 11/12/2023 |
0.3.1 | 110 | 11/10/2023 |
0.3.0 | 105 | 11/10/2023 |
0.2.14 | 110 | 11/9/2023 |
0.2.13 | 107 | 11/8/2023 |
0.2.12 | 97 | 11/7/2023 |
0.2.10 | 101 | 11/7/2023 |
0.2.9 | 110 | 11/6/2023 |
0.2.7 | 113 | 11/6/2023 |
0.2.6 | 129 | 11/4/2023 |
0.2.5 | 117 | 11/3/2023 |
0.2.4 | 112 | 11/2/2023 |
0.2.3 | 112 | 11/2/2023 |
0.2.2 | 118 | 11/2/2023 |
0.2.1 | 110 | 10/30/2023 |
0.2.0 | 101 | 10/30/2023 |
0.1.8 | 122 | 10/28/2023 |
0.1.7 | 106 | 10/24/2023 |
0.1.6 | 99 | 10/24/2023 |
0.1.5 | 117 | 10/24/2023 |
0.1.4 | 115 | 10/24/2023 |
0.1.3 | 114 | 10/20/2023 |
0.1.2-beta | 105 | 10/20/2023 |
0.1.1-beta | 101 | 10/20/2023 |