Last active
January 10, 2021 14:45
-
-
Save zleao/cce569fe9e0f162f399e7a2e03581973 to your computer and use it in GitHub Desktop.
Examples of subscriptions using zoft.NotificationService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OneWay Subscription Examples | |
// Subscribe OneWay message with default context, using a weak reference | |
var token = NotificationService.Subscribe<MyMessage>(HandleOneWaySubscriptionAsync); | |
var token = NotificationService.Subscribe(typeof(MyMessage), HandleOneWaySubscriptionAsync); | |
// Subscribe OneWay message with specified context, using a weak reference | |
var token = NotificationService.Subscribe<MyMessage>(HandleOneWaySubscriptionAsync, "myContext"); | |
var token = NotificationService.Subscribe(typeof(MyMessage), HandleOneWaySubscriptionAsync, "myContext"); | |
// Subscribe OneWay message with specified context with the specified reference type (weak or strong) | |
var token = NotificationService.Subscribe<MyMessage>(HandleOneWaySubscriptionAsync, "myContext", SubscriptionReferenceTypeEnum.Weak); | |
var token = NotificationService.Subscribe(typeof(MyMessage), HandleOneWaySubscriptionAsync, "myContext", SubscriptionReferenceTypeEnum.Weak); | |
private Task HandleOneWaySubscriptionAsync(MyMessage msg) | |
{ | |
//Some handling logic | |
} | |
// TwoWay Subscription Examples | |
// Subscribe TwoWay message with default context, using a weak reference | |
var token = NotificationService.Subscribe<MyMessage, MyResult>(HandleTwoWaySubscriptionAsync); | |
var token = NotificationService.Subscribe(typeof(MyMessage), typeof(MyResult), HandleTwoWaySubscriptionAsync); | |
// Subscribe TwoWay message with specified context, using a weak reference | |
var token = NotificationService.Subscribe<MyMessage, MyResult>(HandleTwoWaySubscriptionAsync, "myContext"); | |
var token = NotificationService.Subscribe(typeof(MyMessage), typeof(MyResult), HandleTwoWaySubscriptionAsync, "myContext"); | |
// Subscribe TwoWay message with specified context with the specified reference type (weak or strong) | |
var token = NotificationService.Subscribe<MyMessage, MyResult>(HandleTwoWaySubscriptionAsync, "myContext", SubscriptionReferenceTypeEnum.Weak); | |
var token = NotificationService.Subscribe(typeof(MyMessage), typeof(MyResult), HandleTwoWaySubscriptionAsync, "myContext", SubscriptionReferenceTypeEnum.Weak); | |
private Task<MyResult> HandleTwoWaySubscriptionAsync(MyMessage msg) | |
{ | |
//Some handling logic | |
return new MyResult(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment