Skip to content

zleao/zoft.NotificationService

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status NuGet

zoft.NotificationService

Generic C# messaging service to allow communication between different modules. Derived from the MvxExtensions.Plugin.Notification

Provides OneWay and TwoWay message sub/pub capabilities as well as Background and UI thread message subscription. Supports delayed notifications for use cases like the resume of views (Android, iOS, etc...).

A bit of context:

This project is part of the zoft library, which is nothing more than an attempt to put together a set of C# utilities that I've created in my current and past projects.

A lot of this code comes from another library I've developed over the years (MvxExtensions). This library was initialy built to provide some extensions and utilities that work on top of awesome MvvmCross and therefore I never worried to much to have a clean separation of concerns when it comes to MvvmCross libraries dependencies. zoft is my attempt to separate what is not MvvmCross dependent. It starts with code ported from MvxExtentions but it will not stop there...

Get started

Install Nuget Package (zoft.NotificationService)

  • Install-Package zoft.NotificationService -Version 1.0.0
  • dotnet add package zoft.NotificationService --version 1.0.0

Make sure to always use the same service instance

If you're using a DI (Dependency Injection) approach, you can use the provided interface INotificationService. Don't forget to register the service as singleton. As an example: IOContainer.RegisterSingleton<INavigationService, NavigationService>()

If you're not using a DI approach, the important part is to ensure that only one instance is uses throughout the application. You might use a factory or a static property.

Samples

You can find a some samples in my other libraries repositories here and here. Both samples are built for mobile applications using Xamarin but the usage is be similar for other platforms.

How to use

Subscribe

var token = NotificationService.Subscribe<MyMessage>(HandleOneWaySubscriptionAsync);

var token = NotificationService.Subscribe<MyMessage, MyResult>(HandleTwoWaySubscriptionAsync);

Click here for a complete set of the possible subscription methods

Unsubscribe

NotificationService.Unsubscribe(token);

Click here for a complete set of the possible unsubscription methods

Publish

NotificationService.PublishAsync(myMessage);
NotificationService.DelayedPublishAsync(myMessage);
NotificationService.PublishPendingNotificationsAsync(this);

var myResult = NotificationService.PublishAsync<MyResult>(MyMessage);

Click here for a complete set of the possible publish methods

About

Generic C# messaging service to allow communication between modules

Topics

Resources

License

Stars

Watchers

Forks

Languages