Skip to content

MPowerKit/Events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MPowerKit.Events

This library gives you an ability to facilitate communication between loosely coupled components in an application.

NuGet

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

About

Facilitates communication between loosely coupled components in an application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages