|
| 1 | +// Copyright (c) 2024, Codefactors Ltd. |
| 2 | +// |
| 3 | +// Codefactors Ltd licenses this file to you under the following license(s): |
| 4 | +// |
| 5 | +// * The MIT License, see https://opensource.org/license/mit/ |
| 6 | + |
| 7 | +namespace StandardWebhooks; |
| 8 | + |
| 9 | +/// <summary> |
| 10 | +/// Factory for creating <see cref="StandardWebhook"/> instances using the supplied |
| 11 | +/// factory constructor parameters. |
| 12 | +/// </summary> |
| 13 | +/// <remarks>Intended particularly for use in ASP.NET dependency injection scenarios.</remarks> |
| 14 | +public class StandardWebhookFactory : IStandardWebhookFactory |
| 15 | +{ |
| 16 | + private readonly string _signingKey; |
| 17 | + private readonly WebhookConfigurationOptions? _webhookConfigurationOptions; |
| 18 | + |
| 19 | + /// <summary> |
| 20 | + /// Initializes a new instance of the <see cref="StandardWebhookFactory"/> class. |
| 21 | + /// </summary> |
| 22 | + /// <param name="signingKey">Signing key, as byte array.</param> |
| 23 | + /// <param name="webhookConfigurationOptions">Options to set custom header keys.</param> |
| 24 | + public StandardWebhookFactory( |
| 25 | + string signingKey, |
| 26 | + WebhookConfigurationOptions? webhookConfigurationOptions) |
| 27 | + { |
| 28 | + _signingKey = signingKey; |
| 29 | + _webhookConfigurationOptions = webhookConfigurationOptions; |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Creates a new instance of a <see cref="StandardWebhook"/>. |
| 34 | + /// </summary> |
| 35 | + /// <returns>New instance of a <see cref="StandardWebhook"/>.</returns> |
| 36 | + public StandardWebhook CreateWebhook() => |
| 37 | + _webhookConfigurationOptions != null ? |
| 38 | + new StandardWebhook(_signingKey, _webhookConfigurationOptions) : |
| 39 | + new StandardWebhook(_signingKey); |
| 40 | +} |
0 commit comments