2021-03-19 20:15:50 +00:00
|
|
|
using System;
|
|
|
|
|
using Elsa.Activities.Webhooks.ActivityTypes;
|
2021-06-04 08:39:22 +00:00
|
|
|
using Elsa.Activities.Webhooks.Options;
|
2021-03-19 20:15:50 +00:00
|
|
|
using Elsa.Activities.Webhooks.Persistence.Decorators;
|
2021-04-16 10:48:06 +00:00
|
|
|
using Elsa.Services;
|
2021-05-30 11:30:07 +00:00
|
|
|
using Elsa.Webhooks.Abstractions.Persistence;
|
2021-06-01 11:26:43 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-03-19 20:15:50 +00:00
|
|
|
|
2021-06-01 11:26:43 +00:00
|
|
|
namespace Elsa.Activities.Webhooks.Extensions
|
2021-03-19 20:15:50 +00:00
|
|
|
{
|
2021-06-01 11:26:43 +00:00
|
|
|
public static class WebhookOptionsBuilderExtensions
|
2021-03-19 20:15:50 +00:00
|
|
|
{
|
2021-04-07 10:45:34 +00:00
|
|
|
public static ElsaOptionsBuilder AddWebhooks(
|
|
|
|
|
this ElsaOptionsBuilder elsaOptions,
|
2021-06-01 11:26:43 +00:00
|
|
|
Action<WebhookOptionsBuilder>? configure = default)
|
2021-03-19 20:15:50 +00:00
|
|
|
{
|
|
|
|
|
var services = elsaOptions.Services;
|
|
|
|
|
|
|
|
|
|
// Configure Webhooks.
|
2021-06-02 16:42:57 +00:00
|
|
|
var webhookOptionsBuilder = new WebhookOptionsBuilder(elsaOptions.Services);
|
2021-06-01 11:26:43 +00:00
|
|
|
configure?.Invoke(webhookOptionsBuilder);
|
2021-03-19 20:15:50 +00:00
|
|
|
|
|
|
|
|
// Services.
|
2021-06-04 11:11:34 +00:00
|
|
|
|
2021-03-19 20:15:50 +00:00
|
|
|
services
|
2021-03-20 06:45:08 +00:00
|
|
|
.AddScoped<IActivityTypeProvider, WebhookActivityTypeProvider>()
|
2021-06-04 11:11:34 +00:00
|
|
|
.AddScoped(sp =>
|
|
|
|
|
{
|
|
|
|
|
var x = webhookOptionsBuilder.WebhookOptions.WebhookDefinitionStoreFactory(sp);
|
|
|
|
|
return x;
|
|
|
|
|
});
|
2021-03-19 20:15:50 +00:00
|
|
|
|
|
|
|
|
services.Decorate<IWebhookDefinitionStore, InitializingWebhookDefinitionStore>();
|
2021-06-04 11:11:34 +00:00
|
|
|
services.Decorate<IWebhookDefinitionStore, EventPublishingWebhookDefinitionStore>();
|
2021-03-19 20:15:50 +00:00
|
|
|
|
|
|
|
|
return elsaOptions;
|
|
|
|
|
}
|
2021-06-04 08:39:22 +00:00
|
|
|
|
|
|
|
|
|
2021-03-19 20:15:50 +00:00
|
|
|
}
|
|
|
|
|
}
|