The WebhookNotifier Service

As described in the previous chapter, when registering the Webhook Notifier service, a number of services are registered in the container, that are used to manage the subscriptions and to deliver the webhooks to the receiving end-point.

An default implementation of the IWebhookNotifier<TWebhook> service is also registered by the framework, which is the WebhookNotifier<TWebhook> class.

This implementation executes the following steps:

  1. Resolution of any webhook subscriptions matching the event type and the tenant identifier (in case of multi-tenant scenarios).

  2. Transformation of the event into an instance of the webhook, using any service implementing IWebhookDataFactory<TWebhook> registered, that can transform or normalize the event information (eg. resolving a database record from an identifier), for each of the subscription resolved.

  3. Filtering the subscriptions mathing the conditions and criteria configured, against the webhook object constructed in the previous step

  4. Attempt to deliver the webhooks to the receiving end-point of the subscription, eventually retrying in case of failures

  5. Optional logging of the results of the delivery of the webhooks, when a service implementing IWebhookDeliveryResultLogger<TWebhook> is registered in the container

Service Dependencies

Custom Webhook Notifiers

The WebhookNotifier<TWebhook> service is registered as IWebhookNotifier<TWebhook> in the container, and can be resolved as such: in fact it doesn't have any specific extensions to the original contract.

If you plan to implement your own webhook notifier, you can do so by implementing the IWebhookNotifier<TWebhook> interface, and registering it in the container, replacing the default implementation, or by inheriting from the WebhookNotifier<TWebhook> class, and overriding the methods you need to customize (that will save you time and preserve from design issues).

You can replace the default implementation of the IWebhookNotifier<TWebhook> service by registering your own implementation in the container, as follows:

services.AddWebhookNotifier<MyWebhook>()
    .UseNotifier<MyNotifier>();

All other default services will still be registered, and you can still use them in your custom implementation, by injecting them in the constructor of your class.

Last updated