CCSWE.nanoFramework.Mediator 1.0.75

There is a newer version of this package available.
See the version list below for details.
dotnet add package CCSWE.nanoFramework.Mediator --version 1.0.75                
NuGet\Install-Package CCSWE.nanoFramework.Mediator -Version 1.0.75                
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="CCSWE.nanoFramework.Mediator" Version="1.0.75" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CCSWE.nanoFramework.Mediator --version 1.0.75                
#r "nuget: CCSWE.nanoFramework.Mediator, 1.0.75"                
#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 CCSWE.nanoFramework.Mediator as a Cake Addin
#addin nuget:?package=CCSWE.nanoFramework.Mediator&version=1.0.75

// Install CCSWE.nanoFramework.Mediator as a Cake Tool
#tool nuget:?package=CCSWE.nanoFramework.Mediator&version=1.0.75                

Build License NuGet

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 Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.76 0 12/26/2024
1.0.75 70 12/19/2024
1.0.74 112 12/12/2024
1.0.73 85 12/5/2024
1.0.72 93 11/28/2024
1.0.71 81 10/31/2024
1.0.70 90 10/24/2024
1.0.69 100 10/10/2024
1.0.68 90 10/3/2024
1.0.67 92 9/26/2024
1.0.66 92 9/23/2024
1.0.65 91 9/22/2024
1.0.64 91 9/21/2024
1.0.63 114 9/21/2024
1.0.62 132 9/14/2024
1.0.61 108 9/13/2024
1.0.59 104 9/2/2024
1.0.58 105 9/1/2024
1.0.57 101 8/31/2024
1.0.56 103 8/31/2024
1.0.55 129 8/14/2024
1.0.54 125 8/13/2024
1.0.53 115 8/11/2024
1.0.52 112 8/11/2024
1.0.51 117 8/8/2024
1.0.50 103 8/7/2024
1.0.49 113 8/6/2024
1.0.48 85 8/4/2024
1.0.47 82 8/3/2024
1.0.46 91 8/2/2024
1.0.45 96 8/2/2024
1.0.44 86 7/29/2024
1.0.43 74 7/27/2024
1.0.42 89 7/26/2024
1.0.41 86 7/25/2024
1.0.40 99 7/24/2024
1.0.39 112 7/19/2024
1.0.38 101 7/17/2024
1.0.37 96 7/15/2024
1.0.36 89 7/14/2024
1.0.35 107 7/13/2024
1.0.34 100 7/12/2024
1.0.33 123 6/16/2024
1.0.32 105 6/14/2024
1.0.31 106 6/13/2024
1.0.27 104 6/7/2024
1.0.26 112 6/6/2024
1.0.25 106 6/5/2024
1.0.24 107 6/5/2024
1.0.22 106 5/25/2024
1.0.21 109 5/24/2024
1.0.20 101 5/23/2024
1.0.19 115 5/21/2024
1.0.18 117 5/20/2024
1.0.17 108 5/19/2024
1.0.16 113 5/19/2024
1.0.15 117 5/19/2024
1.0.14 105 5/18/2024
1.0.12 109 5/16/2024
1.0.11 121 5/15/2024
1.0.10 92 5/13/2024
1.0.9 97 5/11/2024
1.0.8 100 5/10/2024
1.0.7 113 4/27/2024
1.0.6 115 4/26/2024
1.0.5 114 4/25/2024
1.0.4 112 4/25/2024
1.0.3 122 4/23/2024
1.0.2 120 4/20/2024
1.0.1 117 4/19/2024
1.0.0 118 4/19/2024
0.3.31 116 4/17/2024
0.3.30 128 4/13/2024
0.3.29 102 4/12/2024
0.3.28 118 4/11/2024
0.3.27 113 4/10/2024
0.3.26 111 4/9/2024
0.3.25 115 4/8/2024
0.3.24 98 4/7/2024
0.3.23 125 4/6/2024
0.3.22 113 4/5/2024
0.3.21 109 4/4/2024
0.3.20 111 4/3/2024
0.3.19 121 3/24/2024
0.3.18 126 3/22/2024
0.3.17 111 3/21/2024
0.3.16 155 2/6/2024
0.3.15 118 2/3/2024
0.3.14 115 2/1/2024
0.3.13 107 1/27/2024
0.3.12 105 1/26/2024
0.3.11 247 11/23/2023
0.3.10 135 11/22/2023
0.3.9 137 11/21/2023
0.3.8 151 11/17/2023
0.3.7 151 11/14/2023
0.3.6 129 11/13/2023
0.3.5 137 11/12/2023
0.3.4 134 11/12/2023
0.3.3 128 11/12/2023
0.3.2 124 11/12/2023
0.3.1 142 11/10/2023
0.3.0 135 11/10/2023
0.2.14 143 11/9/2023
0.2.13 138 11/8/2023
0.2.12 127 11/7/2023
0.2.10 150 11/7/2023
0.2.9 188 11/6/2023
0.2.7 190 11/6/2023
0.2.6 159 11/4/2023
0.2.5 152 11/3/2023
0.2.4 144 11/2/2023
0.2.3 142 11/2/2023
0.2.2 148 11/2/2023
0.2.1 141 10/30/2023
0.2.0 132 10/30/2023
0.1.8 157 10/28/2023
0.1.7 140 10/24/2023
0.1.6 140 10/24/2023
0.1.5 155 10/24/2023
0.1.4 152 10/24/2023
0.1.3 149 10/20/2023
0.1.2-beta 142 10/20/2023
0.1.1-beta 135 10/20/2023