NetLah.Extensions.EventAggregator 1.0.0-rc2

Prefix Reserved
This is a prerelease version of NetLah.Extensions.EventAggregator.
dotnet add package NetLah.Extensions.EventAggregator --version 1.0.0-rc2                
NuGet\Install-Package NetLah.Extensions.EventAggregator -Version 1.0.0-rc2                
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="NetLah.Extensions.EventAggregator" Version="1.0.0-rc2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetLah.Extensions.EventAggregator --version 1.0.0-rc2                
#r "nuget: NetLah.Extensions.EventAggregator, 1.0.0-rc2"                
#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 NetLah.Extensions.EventAggregator as a Cake Addin
#addin nuget:?package=NetLah.Extensions.EventAggregator&version=1.0.0-rc2&prerelease

// Install NetLah.Extensions.EventAggregator as a Cake Tool
#tool nuget:?package=NetLah.Extensions.EventAggregator&version=1.0.0-rc2&prerelease                

NetLah.Extensions.EventAggregator - .NET Library

NetLah.Extensions.EventAggregator is a library which contains a set of reusable classes implement Event Aggregator pattern integrated with dependency injection Microsoft.Extensions.DependencyInjection. These classes/interface are IEventAggregator, IRootEventAggregator, IAsyncSubscriber, ISubscriber.

Nuget package

NuGet

Build Status

Build Status

Getting started

Scoped and singleton

services.AddEventAggregator();

services.AddSingleton<RootEvent1Subscriber>();
services.SubscribeAsync<BaseEvent1, RootEvent1Subscriber>(lifetime: SubscriberLifetime.Singleton);

services.AddScoped<Event1Subscriber>();             // IAsyncSubscriber<TEvent>
services.AddScoped<Event2Subscriber>();             // ISubscriber<TEvent>
services.AddScoped<Event3Subscriber>();             // IAsyncSubscriber<TEvent>
services.AddScoped<Event4Subscriber>();             // ISubscriber<TEvent>

services.SubscribeAsync<Event1, Event1Subscriber>();
services.Subscribe<Event2, Event2Subscriber>();
services.SubscribeAsync<IEvent3>(
    (ev, sp, ct) => sp.GetRequiredService<Event3Subscriber>().HandleAsync(ev, ct));
services.Subscribe<Event4>(
    (ev, sp) => sp.GetRequiredService<Event4Subscriber>().Handle(ev));

// IEventAggregator eventAggregator
// both RootEvent1Subscriber and Event1Subscriber subscribe on Event1
await eventAggregator.PublishAsync(new Event1 { Message = message1 });
await eventAggregator.PublishAsync(new Event2 { Payload = payload2 });
await eventAggregator.PublishAsync(new Event3());
await eventAggregator.PublishAsync(new Event4());

Singleton only

services.AddEventAggregator();

services.AddSingleton<RootEvent1Subscriber>();      // IAsyncSubscriber<TEvent>
services.AddSingleton<RootEvent2Subscriber>();
services.SubscribeAsync<Event1, RootEvent1Subscriber>(lifetime: SubscriberLifetime.Singleton);
services.Subscribe<Event2>(
    (ev, sp) => sp.GetRequiredService<RootEvent2Subscriber>().Handle(ev),
    lifetime: SubscriberLifetime.Singleton);

// IRootEventAggregator rootEventAggregator
await rootEventAggregator.PublishAsync(new Event1 { Message = message1 });
await rootEventAggregator.PublishAsync(new Event2 { Payload = payload2 });

Interface subscriber

public interface IAsyncSubscriber<in TEvent> where TEvent : IEvent
{
    Task HandleAsync(TEvent @event, CancellationToken cancellationToken = default);
}

public interface ISubscriber<in TEvent> where TEvent : IEvent
{
    void Handle(TEvent @event);
}

Delegate subscriber

public static IServiceCollection SubscribeAsync<TEvent>(this IServiceCollection services,
    Func<TEvent, IServiceProvider, CancellationToken, Task> handler,
    SubscriberLifetime lifetime = SubscriberLifetime.Scoped);

public static IServiceCollection SubscribeAsync<TEvent>(this IServiceCollection services,
    Func<TEvent, IServiceProvider, Task> handler,
    SubscriberLifetime lifetime = SubscriberLifetime.Scoped);

public static IServiceCollection Subscribe<TEvent>(this IServiceCollection services,
    Action<TEvent, IServiceProvider> handler,
    SubscriberLifetime lifetime = SubscriberLifetime.Scoped);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NetLah.Extensions.EventAggregator:

Package Downloads
Innobate.GenericProcessor

Generic Eventable Processor service.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-rc2 126 3/21/2024
1.0.0-rc1 156 1/13/2024
0.2.1 1,052 1/7/2023
0.2.1-rc1 262 9/14/2022
0.2.0 890 11/15/2021
0.2.0-rc2 35,869 10/18/2021
0.2.0-rc1.1 30,274 10/6/2021
0.2.0-rc1 15,630 9/30/2021
0.1.0 97,448 5/19/2021
0.1.0-preview1 220 5/17/2021