using System; using System.Collections.Generic; using BTCPayServer.Data; using BTCPayServer.Plugins.Emails.Views; using BTCPayServer.Plugins.Webhooks; using BTCPayServer.Plugins.Webhooks.Views; using Microsoft.Extensions.DependencyInjection; namespace BTCPayServer; public static class WebhookExtensions { public static IServiceCollection AddWebhookTriggerProvider(this IServiceCollection services) where T : WebhookTriggerProvider { services.AddSingleton(); services.AddSingleton(o => o.GetRequiredService()); return services; } public static IServiceCollection AddWebhookTriggerViewModels(this IServiceCollection services, IEnumerable viewModels) { foreach(var trigger in viewModels) { var webhookType = trigger.Type; if (trigger.Type.StartsWith("WH-")) throw new ArgumentException("Webhook type cannot start with WH-"); trigger.Type = EmailRuleData.GetWebhookTriggerName(trigger.Type); services.AddSingleton(new AvailableWebhookViewModel(webhookType, trigger.Description)); services.AddSingleton(trigger); } return services; } }