NetLah.Extensions.EventAggregator
0.2.1
Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package NetLah.Extensions.EventAggregator --version 0.2.1
NuGet\Install-Package NetLah.Extensions.EventAggregator -Version 0.2.1
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.1" />
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.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetLah.Extensions.EventAggregator, 0.2.1"
#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=0.2.1 // Install NetLah.Extensions.EventAggregator as a Cake Tool #tool nuget:?package=NetLah.Extensions.EventAggregator&version=0.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
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 | Versions 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.
-
.NETStandard 2.0
- Microsoft.Extensions.Options (>= 3.1.0)
-
.NETStandard 2.1
- Microsoft.Extensions.Options (>= 3.1.0)
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 | 128 | 3/21/2024 |
1.0.0-rc1 | 158 | 1/13/2024 |
0.2.1 | 1,082 | 1/7/2023 |
0.2.1-rc1 | 264 | 9/14/2022 |
0.2.0 | 892 | 11/15/2021 |
0.2.0-rc2 | 35,871 | 10/18/2021 |
0.2.0-rc1.1 | 30,278 | 10/6/2021 |
0.2.0-rc1 | 15,632 | 9/30/2021 |
0.1.0 | 97,450 | 5/19/2021 |
0.1.0-preview1 | 222 | 5/17/2021 |