Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/alfonsovgs/eventaggregatorrx
- Owner: alfonsovgs
- Created: 2019-07-17T04:10:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-09T04:10:15.000Z (over 5 years ago)
- Last Synced: 2024-11-26T21:35:11.703Z (2 months ago)
- Topics: eventaggregator, eventaggregator-pattern, reactivex, wpf
- Language: C#
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
}
}
```