MPowerKit.Events
1.0.2
Prefix Reserved
dotnet add package MPowerKit.Events --version 1.0.2
NuGet\Install-Package MPowerKit.Events -Version 1.0.2
<PackageReference Include="MPowerKit.Events" Version="1.0.2" />
paket add MPowerKit.Events --version 1.0.2
#r "nuget: MPowerKit.Events, 1.0.2"
// Install MPowerKit.Events as a Cake Addin #addin nuget:?package=MPowerKit.Events&version=1.0.2 // Install MPowerKit.Events as a Cake Tool #tool nuget:?package=MPowerKit.Events&version=1.0.2
MPowerKit.Events
This library gives you an ability to facilitate communication between loosely coupled components in an application.
Inspired by Prism's EventAggregator.
Note: Main difference from Prism is that this library does not support different threads event publishing/handling. The event will be handled in that thread it was raised in. Also, code was refactored to use latest .net and c# features.
Usage
Register event aggregator in service collection:
serviceCollection.AddSingleton<IEventAggregator, EventAggregator>();
or use as singleton
EventAggregator.Current.GetEvent<>()
Create an event:
public class SomeEvent : PubSubEvent { }
or generic version
public class SomeGenericEvent : PubSubEvent<payload_type> { }
Subscribe to an event:
IEventAggregator _eventAggregator;
public void EventHandler() { }
_eventAggregator.GetEvent<SomeEvent>().Subscribe(EventHandler);
public void GenericEventHandler(payload_type payload) { }
_eventAggregator.GetEvent<SomeGenericEvent>().Subscribe(GenericEventHandler);
Publish an event:
IEventAggregator _eventAggregator;
_eventAggregator.GetEvent<SomeEvent>().Publish();
_eventAggregator.GetEvent<SomeGenericEvent>().Publish(payload);
Note: you may not unsubscribe from events, because it has weak reference, but better to do unsubscribe
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.