public static IServiceCollection AddSpaceWebHookHandler()

in src/JetBrains.Space.AspNetCore/Experimental/WebHooks/SpaceAddWebHookExtensions.cs [50:76]


    public static IServiceCollection AddSpaceWebHookHandler<TWebHookHandler>(this IServiceCollection services, Action<SpaceWebHookOptions> configureOptions)
        where TWebHookHandler : class, ISpaceWebHookHandler
    {
        // Options
        var optionsName = typeof(TWebHookHandler).Name;
        services.Configure(optionsName, configureOptions); 
        services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<SpaceWebHookOptions>, SpaceSpaceWebHookPostConfigureOptions>());

        services.AddOptions<SpaceWebHookOptions>(optionsName)
            .Validate(o => o.VerifySigningKey is not { IsEnabled: true } || !string.IsNullOrEmpty(o.VerifySigningKey.EndpointSigningKey), "Space.VerifySigningKey.EndpointSigningKey is required.")
            .Validate(o => o.VerifyHttpBearerToken is not { IsEnabled: true } || !string.IsNullOrEmpty(o.VerifyHttpBearerToken.BearerToken), "Space.VerifyHttpBearerToken.BearerToken is required.")
            .Validate(o => o.VerifyHttpBasicAuthentication is not { IsEnabled: true } || !string.IsNullOrEmpty(o.VerifyHttpBasicAuthentication.Username), "Space.VerifyHttpBasicAuthentication.Username is required.")
            .Validate(o => o.VerifyHttpBasicAuthentication is not { IsEnabled: true } || !string.IsNullOrEmpty(o.VerifyHttpBasicAuthentication.Password), "Space.VerifyHttpBasicAuthentication.Password is required.")
            .Validate(o => o.VerifyVerificationToken is not { IsEnabled: true } || !string.IsNullOrEmpty(o.VerifyVerificationToken.EndpointVerificationToken), "Space.VerifyVerificationToken.EndpointVerificationToken is required.");

        // Add webhook handler types
        services.AddScoped<TWebHookHandler>();
        services.AddScoped<SpaceWebHookRequestHandler<TWebHookHandler>>();
            
        // Add authentication handler types
        services.TryAddEnumerable(ServiceDescriptor.Transient<ISpaceEndpointAuthenticationHandler, VerifySigningKeyAuthenticationHandler>());
        services.TryAddEnumerable(ServiceDescriptor.Transient<ISpaceEndpointAuthenticationHandler, VerifyHttpBearerTokenAuthenticationHandler>());
        services.TryAddEnumerable(ServiceDescriptor.Transient<ISpaceEndpointAuthenticationHandler, VerifyHttpBasicAuthenticationHandler>());
        services.TryAddEnumerable(ServiceDescriptor.Transient<ISpaceEndpointAuthenticationHandler, VerifyVerificationTokenAuthenticationHandler>());
            
        return services;
    }