NotificationDelegate Delegate
Assembly: CodeEffects.Rule.Repository.dll
Namespace: CodeEffects.Rule.Repository
Summary
Defines the signature of the method that receives the notifications of the Rule Repository: a request for approval, a declined request, a rule or source version made live or taken offline.
Syntax
public delegate void NotificationDelegate(NotificationAction action, NotificationData data);
Parameters
Assign a method of this type to the Notify property of your repository configuration. The repository keeps no list of who should hear about what. Your application knows its users, what each of them may do, and how to reach them, so the delegate is where you decide who is told and how: an email, a message in a chat channel, a row in your own table. A request for approval, for one, is for the users who may approve and decline requests.
Keep these rules in mind when you write the method:
- The repository calls it after the change is committed, so a notification never reports something that was rolled back.
- It runs on the thread of the request, and the request waits for it. If your work takes time, put it in a queue and return.
- An exception that the method throws is caught and ignored. The change has already happened, and the user is not told that it failed. Handle and log your own errors inside the method.
- When
Notify is null, nothing is raised and nothing is read from the database for the purpose.
Example
using CodeEffects.Rule.Repository;
using CodeEffects.Rule.Repository.Common;
NotificationDelegate notify = (action, data) =>
{
if (action == NotificationAction.ApprovalRequested)
Console.WriteLine($"{data.UserName} asks for approval of {data.RuleName}, version {data.RuleVersionName}");
else if (action == NotificationAction.ApprovalDeclined)
Console.WriteLine($"Declined: {data.Reason}");
};
var config = new Configuration { Notify = notify };