From 9d8805c29b34ccfe5e6044594da8d8399e625ee9 Mon Sep 17 00:00:00 2001 From: Joshua Harms Date: Fri, 5 Jan 2024 00:43:58 -0600 Subject: [PATCH] Add ShopPlanServiceFactory --- .../ServiceCollectionExtensions.cs | 1 + .../Factories/ShopPlanServiceFactory.cs | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 ShopifySharp/Factories/ShopPlanServiceFactory.cs diff --git a/ShopifySharp.Extensions.DependencyInjection/ServiceCollectionExtensions.cs b/ShopifySharp.Extensions.DependencyInjection/ServiceCollectionExtensions.cs index 5caf3cd24..49efe9f91 100644 --- a/ShopifySharp.Extensions.DependencyInjection/ServiceCollectionExtensions.cs +++ b/ShopifySharp.Extensions.DependencyInjection/ServiceCollectionExtensions.cs @@ -128,6 +128,7 @@ public static IServiceCollection AddShopifySharpServiceFactories(this IServiceCo services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); + services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); diff --git a/ShopifySharp/Factories/ShopPlanServiceFactory.cs b/ShopifySharp/Factories/ShopPlanServiceFactory.cs new file mode 100644 index 000000000..b4209d28b --- /dev/null +++ b/ShopifySharp/Factories/ShopPlanServiceFactory.cs @@ -0,0 +1,41 @@ +#nullable enable +// Notice: +// This class is auto-generated from a template. Please do not edit it or change it directly. + +using ShopifySharp.Credentials; +using ShopifySharp.Utilities; +using ShopifySharp.Services; + +namespace ShopifySharp.Factories; + +public interface IShopPlanServiceFactory +{ + /// Creates a new instance of the with the given credentials. + /// The shop's *.myshopify.com URL. + /// An API access token for the shop. + IShopPlanService Create(string shopDomain, string accessToken); + + /// Creates a new instance of the with the given credentials. + /// Credentials for authenticating with the Shopify API. + IShopPlanService Create(ShopifyApiCredentials credentials); +} + +public class ShopPlanServiceFactory(IRequestExecutionPolicy? requestExecutionPolicy = null, IShopifyDomainUtility? shopifyDomainUtility = null) : IShopPlanServiceFactory +{ + /// + public virtual IShopPlanService Create(string shopDomain, string accessToken) + { + IShopPlanService service = shopifyDomainUtility is null ? new ShopPlanService(shopDomain, accessToken) : new ShopPlanService(shopDomain, accessToken, shopifyDomainUtility); + + if (requestExecutionPolicy is not null) + { + service.SetExecutionPolicy(requestExecutionPolicy); + } + + return service; + } + + /// + public virtual IShopPlanService Create(ShopifyApiCredentials credentials) => + Create(credentials.ShopDomain, credentials.AccessToken); +}