CCSWE.nanoFramework.Mediator
1.0.70
See the version list below for details.
dotnet add package CCSWE.nanoFramework.Mediator --version 1.0.70
NuGet\Install-Package CCSWE.nanoFramework.Mediator -Version 1.0.70
<PackageReference Include="CCSWE.nanoFramework.Mediator" Version="1.0.70" />
paket add CCSWE.nanoFramework.Mediator --version 1.0.70
#r "nuget: CCSWE.nanoFramework.Mediator, 1.0.70"
// Install CCSWE.nanoFramework.Mediator as a Cake Addin #addin nuget:?package=CCSWE.nanoFramework.Mediator&version=1.0.70 // Install CCSWE.nanoFramework.Mediator as a Cake Tool #tool nuget:?package=CCSWE.nanoFramework.Mediator&version=1.0.70
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.41)
- CCSWE.nanoFramework.Core (>= 1.0.39)
- CCSWE.nanoFramework.Threading (>= 1.0.62)
- nanoFramework.CoreLibrary (>= 1.15.5)
- nanoFramework.DependencyInjection (>= 1.1.3)
- nanoFramework.Logging (>= 1.1.113)
- nanoFramework.System.Collections (>= 1.5.45)
- 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.71 | 67 | 10/31/2024 |
1.0.70 | 80 | 10/24/2024 |
1.0.69 | 89 | 10/10/2024 |
1.0.68 | 81 | 10/3/2024 |
1.0.67 | 80 | 9/26/2024 |
1.0.66 | 84 | 9/23/2024 |
1.0.65 | 83 | 9/22/2024 |
1.0.64 | 81 | 9/21/2024 |
1.0.63 | 104 | 9/21/2024 |
1.0.62 | 124 | 9/14/2024 |
1.0.61 | 98 | 9/13/2024 |
1.0.59 | 96 | 9/2/2024 |
1.0.58 | 94 | 9/1/2024 |
1.0.57 | 93 | 8/31/2024 |
1.0.56 | 93 | 8/31/2024 |
1.0.55 | 117 | 8/14/2024 |
1.0.54 | 115 | 8/13/2024 |
1.0.53 | 105 | 8/11/2024 |
1.0.52 | 104 | 8/11/2024 |
1.0.51 | 107 | 8/8/2024 |
1.0.50 | 93 | 8/7/2024 |
1.0.49 | 104 | 8/6/2024 |
1.0.48 | 73 | 8/4/2024 |
1.0.47 | 74 | 8/3/2024 |
1.0.46 | 82 | 8/2/2024 |
1.0.45 | 84 | 8/2/2024 |
1.0.44 | 74 | 7/29/2024 |
1.0.43 | 64 | 7/27/2024 |
1.0.42 | 80 | 7/26/2024 |
1.0.41 | 77 | 7/25/2024 |
1.0.40 | 89 | 7/24/2024 |
1.0.39 | 99 | 7/19/2024 |
1.0.38 | 93 | 7/17/2024 |
1.0.37 | 88 | 7/15/2024 |
1.0.36 | 81 | 7/14/2024 |
1.0.35 | 97 | 7/13/2024 |
1.0.34 | 92 | 7/12/2024 |
1.0.33 | 115 | 6/16/2024 |
1.0.32 | 99 | 6/14/2024 |
1.0.31 | 98 | 6/13/2024 |
1.0.27 | 96 | 6/7/2024 |
1.0.26 | 104 | 6/6/2024 |
1.0.25 | 100 | 6/5/2024 |
1.0.24 | 99 | 6/5/2024 |
1.0.22 | 100 | 5/25/2024 |
1.0.21 | 101 | 5/24/2024 |
1.0.20 | 95 | 5/23/2024 |
1.0.19 | 105 | 5/21/2024 |
1.0.18 | 109 | 5/20/2024 |
1.0.17 | 100 | 5/19/2024 |
1.0.16 | 102 | 5/19/2024 |
1.0.15 | 111 | 5/19/2024 |
1.0.14 | 99 | 5/18/2024 |
1.0.12 | 101 | 5/16/2024 |
1.0.11 | 113 | 5/15/2024 |
1.0.10 | 86 | 5/13/2024 |
1.0.9 | 89 | 5/11/2024 |
1.0.8 | 94 | 5/10/2024 |
1.0.7 | 109 | 4/27/2024 |
1.0.6 | 111 | 4/26/2024 |
1.0.5 | 110 | 4/25/2024 |
1.0.4 | 104 | 4/25/2024 |
1.0.3 | 114 | 4/23/2024 |
1.0.2 | 114 | 4/20/2024 |
1.0.1 | 113 | 4/19/2024 |
1.0.0 | 114 | 4/19/2024 |
0.3.31 | 110 | 4/17/2024 |
0.3.30 | 122 | 4/13/2024 |
0.3.29 | 96 | 4/12/2024 |
0.3.28 | 114 | 4/11/2024 |
0.3.27 | 107 | 4/10/2024 |
0.3.26 | 107 | 4/9/2024 |
0.3.25 | 109 | 4/8/2024 |
0.3.24 | 94 | 4/7/2024 |
0.3.23 | 121 | 4/6/2024 |
0.3.22 | 109 | 4/5/2024 |
0.3.21 | 105 | 4/4/2024 |
0.3.20 | 107 | 4/3/2024 |
0.3.19 | 117 | 3/24/2024 |
0.3.18 | 122 | 3/22/2024 |
0.3.17 | 104 | 3/21/2024 |
0.3.16 | 151 | 2/6/2024 |
0.3.15 | 114 | 2/3/2024 |
0.3.14 | 109 | 2/1/2024 |
0.3.13 | 102 | 1/27/2024 |
0.3.12 | 101 | 1/26/2024 |
0.3.11 | 243 | 11/23/2023 |
0.3.10 | 131 | 11/22/2023 |
0.3.9 | 133 | 11/21/2023 |
0.3.8 | 145 | 11/17/2023 |
0.3.7 | 147 | 11/14/2023 |
0.3.6 | 125 | 11/13/2023 |
0.3.5 | 133 | 11/12/2023 |
0.3.4 | 130 | 11/12/2023 |
0.3.3 | 124 | 11/12/2023 |
0.3.2 | 120 | 11/12/2023 |
0.3.1 | 138 | 11/10/2023 |
0.3.0 | 131 | 11/10/2023 |
0.2.14 | 137 | 11/9/2023 |
0.2.13 | 134 | 11/8/2023 |
0.2.12 | 123 | 11/7/2023 |
0.2.10 | 146 | 11/7/2023 |
0.2.9 | 184 | 11/6/2023 |
0.2.7 | 186 | 11/6/2023 |
0.2.6 | 155 | 11/4/2023 |
0.2.5 | 148 | 11/3/2023 |
0.2.4 | 138 | 11/2/2023 |
0.2.3 | 138 | 11/2/2023 |
0.2.2 | 144 | 11/2/2023 |
0.2.1 | 135 | 10/30/2023 |
0.2.0 | 126 | 10/30/2023 |
0.1.8 | 151 | 10/28/2023 |
0.1.7 | 132 | 10/24/2023 |
0.1.6 | 134 | 10/24/2023 |
0.1.5 | 148 | 10/24/2023 |
0.1.4 | 146 | 10/24/2023 |
0.1.3 | 143 | 10/20/2023 |
0.1.2-beta | 138 | 10/20/2023 |
0.1.1-beta | 131 | 10/20/2023 |