aspnet / AspNetWebHooks

Libraries to create and consume web hooks on ASP.NET 4.x (Due to other priorities this project is currently in maintenance mode only. There are no planned releases at this time. No new features are planned and we are only addressing critical issues as required.)
Apache License 2.0
134 stars 103 forks source link

Call NotifyAsync out of a controller #144

Open rukshanfonseka opened 2 years ago

rukshanfonseka commented 2 years ago

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 commented 2 years ago

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);
}