diff --git a/src/StandardWebhooks/IStandardWebhookFactory.cs b/src/StandardWebhooks/IStandardWebhookFactory.cs new file mode 100644 index 0000000..83a7d84 --- /dev/null +++ b/src/StandardWebhooks/IStandardWebhookFactory.cs @@ -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; + +/// +/// Interface for factories that can create instances. +/// +/// Intended particularly for use in ASP.NET dependency injection scenarios. +public interface IStandardWebhookFactory +{ + /// + /// Creates a new instance of a . + /// + /// New instance of a . + StandardWebhook CreateWebhook(); +} diff --git a/src/StandardWebhooks/StandardWebhookFactory.cs b/src/StandardWebhooks/StandardWebhookFactory.cs new file mode 100644 index 0000000..0ed5371 --- /dev/null +++ b/src/StandardWebhooks/StandardWebhookFactory.cs @@ -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; + +/// +/// Factory for creating instances using the supplied +/// factory constructor parameters. +/// +/// Intended particularly for use in ASP.NET dependency injection scenarios. +public class StandardWebhookFactory : IStandardWebhookFactory +{ + private readonly string _signingKey; + private readonly WebhookConfigurationOptions? _webhookConfigurationOptions; + + /// + /// Initializes a new instance of the class. + /// + /// Signing key, as byte array. + /// Options to set custom header keys. + public StandardWebhookFactory( + string signingKey, + WebhookConfigurationOptions? webhookConfigurationOptions) + { + _signingKey = signingKey; + _webhookConfigurationOptions = webhookConfigurationOptions; + } + + /// + /// Creates a new instance of a . + /// + /// New instance of a . + public StandardWebhook CreateWebhook() => + _webhookConfigurationOptions != null ? + new StandardWebhook(_signingKey, _webhookConfigurationOptions) : + new StandardWebhook(_signingKey); +}