NetLah.Extensions.EventAggregator 0.2.0

The ID prefix of this package has been reserved for one of the owners of this package by Prefix Reserved
.NET Standard 2.0
There is a newer version of this package available.
See the version list below for details.
dotnet add package NetLah.Extensions.EventAggregator --version 0.2.0
NuGet\Install-Package NetLah.Extensions.EventAggregator -Version 0.2.0
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="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetLah.Extensions.EventAggregator --version 0.2.0
#r "nuget: NetLah.Extensions.EventAggregator, 0.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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=0.2.0

// Install NetLah.Extensions.EventAggregator as a Cake Tool
#tool nuget:?package=NetLah.Extensions.EventAggregator&version=0.2.0

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


Build Status

Build Status

Getting started

Scoped and singleton


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>();
    (ev, sp, ct) => sp.GetRequiredService<Event3Subscriber>().HandleAsync(ev, ct));
    (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.AddSingleton<RootEvent1Subscriber>();      // IAsyncSubscriber<TEvent>
services.SubscribeAsync<Event1, RootEvent1Subscriber>(lifetime: SubscriberLifetime.Singleton);
    (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 Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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

Generic Eventable Processor service.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.1 101 1/7/2023
0.2.1-rc1 138 9/14/2022
0.2.0 470 11/15/2021
0.2.0-rc2 35,786 10/18/2021
0.2.0-rc1.1 30,208 10/6/2021
0.2.0-rc1 15,569 9/30/2021
0.1.0 97,318 5/19/2021
0.1.0-preview1 132 5/17/2021