< Summary

Information
Class: Intentum.Events.EventsExtensions
Assembly: Intentum.Events
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Events/EventsExtensions.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 51
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
AddIntentumEvents(...)100%22100%
AddWebhook(...)100%44100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Events/EventsExtensions.cs

#LineLine coverage
 1using JetBrains.Annotations;
 2using Microsoft.Extensions.DependencyInjection;
 3
 4namespace Intentum.Events;
 5
 6/// <summary>
 7/// Extension methods for registering Intentum events with dependency injection.
 8/// </summary>
 9[UsedImplicitly]
 10public static class EventsExtensions
 11{
 12    /// <summary>
 13    /// Adds Intentum event handling (webhooks) to the service collection.
 14    /// </summary>
 15    /// <param name="services">The service collection.</param>
 16    /// <param name="configure">Action to configure webhooks and retry.</param>
 17    /// <returns>The service collection for chaining.</returns>
 18    [UsedImplicitly]
 19    public static IServiceCollection AddIntentumEvents(
 20        this IServiceCollection services,
 21        Action<IntentumEventsOptions>? configure = null)
 122    {
 123        services.AddOptions<IntentumEventsOptions>();
 124        if (configure != null)
 125            services.Configure(configure);
 26
 127        services.AddHttpClient(IntentumEventsOptions.HttpClientName);
 28
 129        services.AddScoped<IIntentEventHandler, WebhookIntentEventHandler>();
 130        return services;
 131    }
 32
 33    /// <summary>
 34    /// Adds a webhook to the events options. Call from within Configure(IntentumEventsOptions).
 35    /// </summary>
 36    [UsedImplicitly]
 37    public static IntentumEventsOptions AddWebhook(
 38        this IntentumEventsOptions options,
 39        string url,
 40        IEnumerable<string>? events = null)
 941    {
 942        var eventTypes = events?.ToHashSet(StringComparer.OrdinalIgnoreCase)
 943            ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase)
 944            {
 945                nameof(IntentumEventType.IntentInferred),
 946                nameof(IntentumEventType.PolicyDecisionChanged)
 947            };
 948        options.Webhooks.Add(new WebhookConfig { Url = url, EventTypes = eventTypes });
 949        return options;
 950    }
 51}