Skip to content

A portable event aggregator for pub-sub messaging, using Rx, for .NET 4+, SL5, WP8+ and Windows Store Apps

License

Notifications You must be signed in to change notification settings

carlosagsmendes/Reactive.EventAggregator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reactive.EventAggreator

This is an update of a blog post from José F. Romaniello about using Reactive Extensions to implement an event aggregator. source

Build status

Usage

To install it, just run this from the Package Manager Console:

Install-Package Reactive.EventAggregator

Why bring it back?

Three reasons:

  • I wanted a simple event aggregator, without taking a dependency on an MVVM framework
  • It should be available on NuGet
  • Demonstrate Portable Class Libaries and targetting different platforms from one codebase

Samples

Subscribing to an event

// arrange
var eventWasRaised = false;
var eventPublisher = new EventAggregator();

// act
eventPublisher.GetEvent<SampleEvent>()
              .Subscribe(se => eventWasRaised = true);

eventPublisher.Publish(new SampleEvent());

// assert
eventWasRaised.ShouldBe(true);

Disposing of the event

// arrange
var eventWasRaised = false;
var eventPublisher = new EventAggregator();

// act
var subscription = eventPublisher.GetEvent<SampleEvent>()
                                 .Subscribe(se => eventWasRaised = true);

subscription.Dispose();
eventPublisher.Publish(new SampleEvent());

// assert
eventWasRaised.ShouldBe(false);

Selectively subscribing to an event

// arrange
var eventWasRaised = false;
var eventPublisher = new EventAggregator();

// act
eventPublisher.GetEvent<SampleEvent>()
              .Where(se => se.Status == 1)
              .Subscribe(se => eventWasRaised = true);

eventPublisher.Publish(new SampleEvent { Status = 1 });

// assert
eventWasRaised.ShouldBe(true);

About

A portable event aggregator for pub-sub messaging, using Rx, for .NET 4+, SL5, WP8+ and Windows Store Apps

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 86.6%
  • PowerShell 13.4%