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...).
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...
Install Nuget Package (zoft.NotificationService)
Install-Package zoft.NotificationService -Version 1.0.0dotnet add package zoft.NotificationService --version 1.0.0
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.
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.
var token = NotificationService.Subscribe<MyMessage>(HandleOneWaySubscriptionAsync);
var token = NotificationService.Subscribe<MyMessage, MyResult>(HandleTwoWaySubscriptionAsync);
Click here for a complete set of the possible subscription methods
NotificationService.Unsubscribe(token);
Click here for a complete set of the possible unsubscription methods
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