diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.DXA/Factories/DependencyFactory.cs b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.DXA/Factories/DependencyFactory.cs index 8df2a91..43bee9d 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.DXA/Factories/DependencyFactory.cs +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.DXA/Factories/DependencyFactory.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; using System.Threading; - + using Rest; using SDL.ECommerce.Api; using SDL.ECommerce.DXA.Providers; using SDL.ECommerce.DXA.Servants; @@ -22,7 +22,8 @@ public T Resolve() { typeof(IECommerceLinkResolver), new Lazy(() => TryResolveDependency() ?? new DXALinkResolver()) }, { typeof(IHttpContextServant), new Lazy(() => TryResolveDependency() ?? new HttpContextServant()) }, { typeof(IPageModelServant), new Lazy(() => TryResolveDependency() ?? new PageModelServant()) }, - { typeof(IPathServant), new Lazy(() => TryResolveDependency() ?? new PathServant()) } + { typeof(IPathServant), new Lazy(() => TryResolveDependency() ?? new PathServant()) }, + { typeof(RestClientFactory), new Lazy(() => TryResolveDependency() ?? new RestClientFactory()) } }; var dependency = dependencies[typeof(T)]; diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.OData/SDL.ECommerce.OData.csproj b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.OData/SDL.ECommerce.OData.csproj index b551794..e3141b5 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.OData/SDL.ECommerce.OData.csproj +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.OData/SDL.ECommerce.OData.csproj @@ -96,9 +96,8 @@ ..\packages\Microsoft.Spatial.6.15.0\lib\portable-net45+win+wpa81\Microsoft.Spatial.dll True - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - True + + ..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll ..\packages\Sdl.Web.Delivery.10.1.0\lib\net452\Sdl.Web.Delivery.DiscoveryService.dll diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.OData/packages.config b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.OData/packages.config index b96700c..543cdb4 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.OData/packages.config +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.OData/packages.config @@ -16,7 +16,7 @@ - + diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/ECommerceClient.cs b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/ECommerceClient.cs index 9f7af8a..b4a896a 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/ECommerceClient.cs +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/ECommerceClient.cs @@ -9,7 +9,7 @@ namespace SDL.ECommerce.Rest public class ECommerceClient : IECommerceClient { private readonly Func dependencies; - private readonly RestClient restClient; + private readonly IRestClient restClient; private readonly IECommerceCacheProvider cacheProvider; private readonly int categoryExpiryTimeout; private readonly bool useSanitizedPathNames; @@ -27,11 +27,14 @@ public ECommerceClient(string endpointAddress, bool useSanitizedPathNames, Func dependencies = null) { - this.restClient = new RestClient(endpointAddress + "/rest/v1/" + locale); + this.dependencies = dependencies; + this.cacheProvider = cacheProvider; this.categoryExpiryTimeout = categoryExpiryTimeout; this.useSanitizedPathNames = useSanitizedPathNames; - this.dependencies = dependencies; + + var restClientFactory = Resolve() ?? new RestClientFactory(); + restClient = restClientFactory.CreateClient(endpointAddress, locale); } public ICartService CartService diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/RestClientFactory.cs b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/RestClientFactory.cs new file mode 100644 index 0000000..888f742 --- /dev/null +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/RestClientFactory.cs @@ -0,0 +1,12 @@ +namespace SDL.ECommerce.Rest +{ + using RestSharp; + + public class RestClientFactory + { + public virtual IRestClient CreateClient(string endpointAddress, string locale, string apiVersion = "v1") + { + return new RestClient(string.Format("{0}/rest/{1}/{2}", endpointAddress, apiVersion, locale)); + } + } +} \ No newline at end of file diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/SDL.ECommerce.Rest.csproj b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/SDL.ECommerce.Rest.csproj index 29c3791..177e534 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/SDL.ECommerce.Rest.csproj +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/SDL.ECommerce.Rest.csproj @@ -31,9 +31,8 @@ 4 - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - True + + ..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll @@ -75,6 +74,7 @@ + diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/CartService.cs b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/CartService.cs index 8865e75..9cd07ed 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/CartService.cs +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/CartService.cs @@ -1,9 +1,6 @@ using SDL.ECommerce.Api.Service; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using SDL.ECommerce.Api.Model; using RestSharp; using Newtonsoft.Json; @@ -14,9 +11,9 @@ namespace SDL.ECommerce.Rest.Service { public class CartService : ICartService { - private RestClient restClient; + private IRestClient restClient; - public CartService(RestClient restClient) + public CartService(IRestClient restClient) { this.restClient = restClient; } diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/EditService.cs b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/EditService.cs index fe65d99..85d31a9 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/EditService.cs +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/EditService.cs @@ -1,9 +1,4 @@ using SDL.ECommerce.Api.Service; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using SDL.ECommerce.Api.Model; using RestSharp; using Newtonsoft.Json; @@ -14,10 +9,10 @@ namespace SDL.ECommerce.Rest.Service { class EditService : IEditService { - private RestClient restClient; + private IRestClient restClient; private IECommerceCacheProvider cacheProvider; - public EditService(RestClient restClient, IECommerceCacheProvider cacheProvider) + public EditService(IRestClient restClient, IECommerceCacheProvider cacheProvider) { this.restClient = restClient; this.cacheProvider = cacheProvider; diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductCategoryService.cs b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductCategoryService.cs index 40450e7..c0a10d7 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductCategoryService.cs +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductCategoryService.cs @@ -5,7 +5,6 @@ using SDL.ECommerce.Api.Model; using RestSharp; using SDL.ECommerce.Rest.Model; -using SDL.ECommerce.Api; using SDL.ECommerce.Formatting.Servants; namespace SDL.ECommerce.Rest.Service @@ -15,13 +14,13 @@ namespace SDL.ECommerce.Rest.Service /// class ProductCategoryService : IProductCategoryService { - private RestClient restClient; + private IRestClient restClient; private int categoryExpiryTimeout = 3600000; private bool useSanitizedPathNames = false; private ICategory rootCategory = new Category(); private readonly ISanitizerServant _sanitizerServant; - public ProductCategoryService(RestClient restClient, int categoryExpiryTimeout, bool useSanitizedPathNames) + public ProductCategoryService(IRestClient restClient, int categoryExpiryTimeout, bool useSanitizedPathNames) { this.restClient = restClient; this.useSanitizedPathNames = useSanitizedPathNames; diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductDetailService.cs b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductDetailService.cs index c45eefb..26eebb2 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductDetailService.cs +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductDetailService.cs @@ -6,8 +6,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SDL.ECommerce.Rest.Service { @@ -16,11 +14,11 @@ namespace SDL.ECommerce.Rest.Service /// public class ProductDetailService : IProductDetailService { - private RestClient restClient; + private IRestClient restClient; private IProductCategoryService productCategoryService; private IECommerceCacheProvider cacheProvider; - public ProductDetailService(RestClient restClient, IProductCategoryService productCategoryService, IECommerceCacheProvider cacheProvider) + public ProductDetailService(IRestClient restClient, IProductCategoryService productCategoryService, IECommerceCacheProvider cacheProvider) { this.restClient = restClient; this.productCategoryService = productCategoryService; diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductQueryService.cs b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductQueryService.cs index 1854260..4ccd7a6 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductQueryService.cs +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/Service/ProductQueryService.cs @@ -1,9 +1,6 @@ using SDL.ECommerce.Api.Service; using System; -using System.Collections.Generic; -using System.Linq; using System.Text; -using System.Threading.Tasks; using SDL.ECommerce.Api.Model; using RestSharp; using SDL.ECommerce.Rest.Model; @@ -18,10 +15,10 @@ namespace SDL.ECommerce.Rest.Service class ProductQueryService : IProductQueryService { - private RestClient restClient; + private IRestClient restClient; private IECommerceCacheProvider cacheProvider; - public ProductQueryService(RestClient restClient, IECommerceCacheProvider cacheProvider) + public ProductQueryService(IRestClient restClient, IECommerceCacheProvider cacheProvider) { this.restClient = restClient; this.cacheProvider = cacheProvider; diff --git a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/packages.config b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/packages.config index e09901c..f04b155 100644 --- a/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/packages.config +++ b/dxa.net/ecommerce-framework-dotnet/SDL.ECommerce.Rest/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file