-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added factory for standard webhooks, especially useful for di s…
…cenarios
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |