Lea 1.5.0
See the version list below for details.
dotnet add package Lea --version 1.5.0
NuGet\Install-Package Lea -Version 1.5.0
<PackageReference Include="Lea" Version="1.5.0" />
paket add Lea --version 1.5.0
#r "nuget: Lea, 1.5.0"
// Install Lea as a Cake Addin #addin nuget:?package=Lea&version=1.5.0 // Install Lea as a Cake Tool #tool nuget:?package=Lea&version=1.5.0
Lite Event Aggregator (Lea)
Lea is an implementation of the event aggregator pattern which decouples event senders and consumers. Consuming classes subscribe to events by registering handler methods. Lea supports both synchronous and asynchronous handlers.
{
eventAggregactor.Subscribe<MyEvent>(MyEventHandler);
eventAggregactor.Subscribe<MyEvent>(AsyncMyEventHandler);
}
private void MyEventHandler(MyEvent evt)
{
// handling code here
}
private async Task AsyncMyEventHandler(MyEvent evt)
{
// handling code here
}
The handler is called by EventAggregator whenever the MyEvent event is published:
{
eventAggregator.Publish(new MyEvent());
}
Events must be classes that implement the Lea.IEvent interface. There are no other restrictions on the event class implementation.
public class MyEvent : IEvent
{
public string Value { get; set; }
}
Lea keeps only weak references to handlers so will not prevent garbage collection of any object with a method registered as a handler.
Handler methods may be unsubscribed to stop receiveing events either by passing the method delegate or the token object returned when subscribed to EventAggregator.Unsubscribe(). If the handler method goes out of scope and its containing object is garbage collected, EventAggregator will clean itself up and automatically remove the missing subscription.
{
var myEventHandlerToken = eventAggregactor.Subscribe<MyEvent>(MyEventHandler);
var asyncMyEventHandlerToken = eventAggregactor.Subscribe<MyEvent>(AsyncMyEventHandler);
...
eventAggregator.Unsubscribe<MyEvent>(myEventHandlerToken); // unsub with token
eventAggregator.Unsubscribe<MyEvent>(AsyncMyEventHandler); // unsub with delegate
}
Lea is thread-safe, supporting recursive reads.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
-
net7.0
- CommunityToolkit.Diagnostics (>= 8.2.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Lea:
Package | Downloads |
---|---|
Dorico.Net
A library for working with Dorico's remote control API |
GitHub repositories
This package is not used by any popular GitHub repositories.
Improved WeakReferences to delegate owner objects.