Skip to content

Commit

Permalink
feat: added factory for standard webhooks, especially useful for di s…
Browse files Browse the repository at this point in the history
…cenarios
  • Loading branch information
payetools committed Sep 14, 2024
1 parent c8409b0 commit 825ee51
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/StandardWebhooks/IStandardWebhookFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2024, Codefactors Ltd.
//
// Codefactors Ltd licenses this file to you under the following license(s):
//
// * The MIT License, see https://opensource.org/license/mit/

namespace StandardWebhooks;

/// <summary>
/// Interface for factories that can create <see cref="StandardWebhook"/> instances.
/// </summary>
/// <remarks>Intended particularly for use in ASP.NET dependency injection scenarios.</remarks>
public interface IStandardWebhookFactory
{
/// <summary>
/// Creates a new instance of a <see cref="StandardWebhook"/>.
/// </summary>
/// <returns>New instance of a <see cref="StandardWebhook"/>.</returns>
StandardWebhook CreateWebhook();
}
40 changes: 40 additions & 0 deletions src/StandardWebhooks/StandardWebhookFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2024, Codefactors Ltd.
//
// Codefactors Ltd licenses this file to you under the following license(s):
//
// * The MIT License, see https://opensource.org/license/mit/

namespace StandardWebhooks;

/// <summary>
/// Factory for creating <see cref="StandardWebhook"/> instances using the supplied
/// factory constructor parameters.
/// </summary>
/// <remarks>Intended particularly for use in ASP.NET dependency injection scenarios.</remarks>
public class StandardWebhookFactory : IStandardWebhookFactory
{
private readonly string _signingKey;
private readonly WebhookConfigurationOptions? _webhookConfigurationOptions;

/// <summary>
/// Initializes a new instance of the <see cref="StandardWebhookFactory"/> class.
/// </summary>
/// <param name="signingKey">Signing key, as byte array.</param>
/// <param name="webhookConfigurationOptions">Options to set custom header keys.</param>
public StandardWebhookFactory(
string signingKey,
WebhookConfigurationOptions? webhookConfigurationOptions)
{
_signingKey = signingKey;
_webhookConfigurationOptions = webhookConfigurationOptions;
}

/// <summary>
/// Creates a new instance of a <see cref="StandardWebhook"/>.
/// </summary>
/// <returns>New instance of a <see cref="StandardWebhook"/>.</returns>
public StandardWebhook CreateWebhook() =>
_webhookConfigurationOptions != null ?
new StandardWebhook(_signingKey, _webhookConfigurationOptions) :
new StandardWebhook(_signingKey);
}

0 comments on commit 825ee51

Please sign in to comment.