AspNetWebHooks icon indicating copy to clipboard operation
AspNetWebHooks copied to clipboard

Call NotifyAsync out of a controller

Open rukshanfonseka opened this issue 3 years ago • 1 comments

Can someone let me know if it is possible to call the custom webhook's NotifyAsync outside of a MVC or WebApi controller? I already send webhooks within controllers but now also need to add NotifyAsync to a WCF callback. I cannot see how I can get access to the Web hook manager.

rukshanfonseka avatar Aug 15 '22 01:08 rukshanfonseka

Ok after much trolling through the library code this works

// this can be used outside of a MVC or WebAPI controller
public static async Task NotifyAsync(string action, object data)
{
    var logger = CommonServices.GetLogger();
    var store = CustomServices.GetStore();
    var sender = CustomServices.GetSender(logger);
    var manager = new WebHookManager(store, sender, logger);
    var notifications = new NotificationDictionary[] { new NotificationDictionary(action, data) };
    await manager.NotifyAllAsync(notifications, null);
}

rukshanfonseka avatar Aug 15 '22 02:08 rukshanfonseka