Lea 1.5.0

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

Version Downloads Last updated
1.5.1 132 3/14/2024
1.5.0 124 3/13/2024
1.4.0 203 1/2/2024
1.3.0 224 12/3/2023
1.2.0 137 11/24/2023
1.1.0 128 11/23/2023
1.0.0 112 11/20/2023

Improved WeakReferences to delegate owner objects.