Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alfonsovgs/eventaggregatorrx

Simple EventAggregator class using Rx.
https://github.com/alfonsovgs/eventaggregatorrx

eventaggregator eventaggregator-pattern reactivex wpf

Last synced: about 1 month ago
JSON representation

Simple EventAggregator class using Rx.

Awesome Lists containing this project

README

        

# EventAggregatorRx
Simple EventAggregator class using Rx.

## Download
### Via NuGet
To install library by using [Nuget package](https://www.nuget.org/packages/EventAggregatorRx) manager execute next command:

```
Install-Package EventAggregatorRx -Version 1.0.0.1
```

## Example
Design events using IEvent interface.

```csharp
public class ItemAdded : IEvent
{
public Guid ItemId {get; set;}
}
```

Next step, implement your events in the viewModel and subscribe.

```csharp
public class BasketViewModel : IEventHandler
{
...
public BasketViewModel(IEventAggregator event)
{
eventAggregator.Subscribe(this); //subscribing viewmodel
}

public void Handle(ItemAdded @event)
{
//TODO: Any action
}
}
```

Next step: Publish the event in another viewmodel.

```csharp
public class CatalogViewModel
{
...
public CatalogViewModel(IEventAggregator eventAggregator)
{
eventAggregator.Publish(new ItemAdded {ItemId = Guid.NewGuid()});
}
}
```

## Method Extensions

You can use method extensions to simplify

```csharp
public class CatalogViewModel
{
...
public CatalogViewModel(IEventAggregator eventAggregator)
{
eventAggregator.Publish(x => ItemId = Guid.NewGuid());
eventAggregator.Publish(); //If the event no has data
}
}
```