MakoIoT.Device.Services.Mediator
1.0.57.42352
dotnet add package MakoIoT.Device.Services.Mediator --version 1.0.57.42352
NuGet\Install-Package MakoIoT.Device.Services.Mediator -Version 1.0.57.42352
<PackageReference Include="MakoIoT.Device.Services.Mediator" Version="1.0.57.42352" />
paket add MakoIoT.Device.Services.Mediator --version 1.0.57.42352
#r "nuget: MakoIoT.Device.Services.Mediator, 1.0.57.42352"
// Install MakoIoT.Device.Services.Mediator as a Cake Addin #addin nuget:?package=MakoIoT.Device.Services.Mediator&version=1.0.57.42352 // Install MakoIoT.Device.Services.Mediator as a Cake Tool #tool nuget:?package=MakoIoT.Device.Services.Mediator&version=1.0.57.42352
Mako-IoT.Device.Services.Mediator
Mediator pattern implementation. Provides in-process publisher-subscriber communication while keeping all parties decoupled.
Usage
See Mediator sample
Create classes for your events
public class Event1 : IEvent
{
public string Data { get; set; }
}
public class Event2 : IEvent
{
public string Text { get; set; }
}
Your event subscriber must implement IEventHandler interface
public class Service2 : IEventHandler
{
public void Handle(IEvent @event)
{
switch (@event)
{
case Event1 event1:
Debug.WriteLine($"[{nameof(Service2)}] Event1 received. The data is: {event1.Data}");
break;
case Event2 event2:
Debug.WriteLine($"[{nameof(Service2)}] Event2 received The text is: {event2.Text}");
break;
}
}
}
Use IMediator to publish events
public class Service1 : IService1
{
private readonly IMediator _mediator;
public Service1(IMediator mediator)
{
_mediator = mediator;
}
public void DoSomething()
{
_mediator.Publish(new Event2 { Text = "Hello from Service1 !" });
}
}
Register Mediator and singleton subscribers in DeviceBuilder
DeviceBuilder.Create()
.AddMediator(options =>
{
options.AddSubscriber(typeof(Event1), typeof(Service2));
options.AddSubscriber(typeof(Event2), typeof(Service2));
})
.Build()
.Start()
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. |
-
- MakoIoT.Device.Services.Interface (>= 1.0.48.22567)
- nanoFramework.CoreLibrary (>= 1.15.5)
- nanoFramework.DependencyInjection (>= 1.1.11)
- nanoFramework.System.Collections (>= 1.5.45)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on MakoIoT.Device.Services.Mediator:
Package | Downloads |
---|---|
MakoIoT.Device.Services.ConfigurationManager
Configuration mode manager for MAKO-IoT |
|
MakoIoT.Device.Services.ConfigurationApi
REST API for configuration with MAKO-IoT |
|
MakoIoT.Device.Platform.LocalConfig
MAKO-IoT Platform local configuration library. On-device web server, WiFi AP |
|
MakoIoT.Device.Services.Logging.Storage
Logging to flash storage and logs upload to Elasticsearch for MAKO-IoT |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.57.42352 | 254 | 11/28/2024 |
1.0.56.4697 | 150 | 11/27/2024 |
1.0.55.2648 | 158 | 11/26/2024 |
1.0.54.41107 | 167 | 11/25/2024 |
1.0.53.51021 | 353 | 11/19/2024 |
1.0.52.56154 | 827 | 10/18/2024 |
1.0.51.44660 | 229 | 10/16/2024 |
1.0.50.63396 | 483 | 9/26/2024 |
1.0.49.59837 | 393 | 9/20/2024 |
1.0.48.59964 | 426 | 9/12/2024 |
1.0.47.39935 | 509 | 8/27/2024 |
1.0.46.45075 | 445 | 8/10/2024 |
1.0.45.63754 | 225 | 8/5/2024 |
1.0.44.7886 | 696 | 6/12/2024 |
1.0.43.57607 | 1,045 | 5/17/2024 |
1.0.42.48945 | 1,342 | 4/8/2024 |
1.0.41.33870 | 793 | 3/22/2024 |
1.0.40.12180 | 244 | 3/21/2024 |
1.0.39.38843 | 2,098 | 1/6/2024 |
1.0.38.6937 | 444 | 12/30/2023 |
1.0.37.22301 | 459 | 12/19/2023 |
1.0.36.36218 | 844 | 12/1/2023 |
1.0.35.38046 | 229 | 12/1/2023 |
1.0.34.61610 | 607 | 11/17/2023 |
1.0.33.12388 | 291 | 11/16/2023 |
1.0.32.35604 | 636 | 11/11/2023 |
1.0.31.54540 | 1,126 | 10/12/2023 |
1.0.30.24296 | 900 | 10/6/2023 |
1.0.28.51374 | 314 | 10/6/2023 |
1.0.26.61682 | 1,981 | 5/24/2023 |
1.0.25.54621 | 210 | 5/24/2023 |
1.0.23.37503 | 293 | 5/23/2023 |
1.0.21.48055 | 162 | 5/22/2023 |
1.0.20.12163 | 388 | 5/22/2023 |