Skip to content

Commit 825ee51

Browse files
committed
feat: added factory for standard webhooks, especially useful for di scenarios
1 parent c8409b0 commit 825ee51

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
/// Interface for factories that can create <see cref="StandardWebhook"/> instances.
11+
/// </summary>
12+
/// <remarks>Intended particularly for use in ASP.NET dependency injection scenarios.</remarks>
13+
public interface IStandardWebhookFactory
14+
{
15+
/// <summary>
16+
/// Creates a new instance of a <see cref="StandardWebhook"/>.
17+
/// </summary>
18+
/// <returns>New instance of a <see cref="StandardWebhook"/>.</returns>
19+
StandardWebhook CreateWebhook();
20+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)