Skip to content

Commit b8e3d17

Browse files
authored
Replace DI of HttpContext in ShippingPriceService by direct injection of IServiceProvider simplcommerce#924 (simplcommerce#925)
1 parent f4a9449 commit b8e3d17

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Modules/SimplCommerce.Module.ShippingPrices/Services/ShippingPriceService.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Http;
65
using Microsoft.EntityFrameworkCore;
76
using Microsoft.Extensions.DependencyInjection;
87
using SimplCommerce.Infrastructure.Data;
@@ -12,20 +11,20 @@ namespace SimplCommerce.Module.ShippingPrices.Services
1211
{
1312
public class ShippingPriceService : IShippingPriceService
1413
{
15-
private HttpContext _httpContext;
14+
private readonly IServiceProvider _serviceProvider;
1615
private readonly IRepositoryWithTypedId<ShippingProvider, string> _shippingProviderRepository;
1716

18-
public ShippingPriceService(IHttpContextAccessor contextAccessor, IRepositoryWithTypedId<ShippingProvider, string> shippingProviderRepository)
17+
public ShippingPriceService(IServiceProvider serviceProvider, IRepositoryWithTypedId<ShippingProvider, string> shippingProviderRepository)
1918
{
20-
_httpContext = contextAccessor.HttpContext;
19+
_serviceProvider = serviceProvider;
2120
_shippingProviderRepository = shippingProviderRepository;
2221
}
2322

2423
public async Task<IList<ShippingPrice>> GetApplicableShippingPrices(GetShippingPriceRequest request)
2524
{
2625
var applicableShippingPrices = new List<ShippingPrice>();
2726
var providers = await _shippingProviderRepository.Query().ToListAsync();
28-
var shippingRateServices = _httpContext.RequestServices.GetServices<IShippingPriceServiceProvider>();
27+
var shippingRateServices = _serviceProvider.GetServices<IShippingPriceServiceProvider>();
2928

3029
foreach(var provider in providers)
3130
{

0 commit comments

Comments
 (0)