Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Further changes with remove IServiceProvider

support27568c1dc9ac
diff --git a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
index 9c838faf1..8e7bcdb5e 100644
--- a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
@@ -32,6 +32,7 @@ using Grand.Web.Admin.Models.Messages;
using Grand.Web.Admin.Models.ShoppingCart;
using Grand.Web.Common.Extensions;
using Grand.Web.Common.Models;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.DependencyInjection;
using System.Net;
@@ -62,7 +63,7 @@ namespace Grand.Web.Admin.Services
private readonly ISalesEmployeeService _salesEmployeeService;
private readonly ICustomerNoteService _customerNoteService;
private readonly IDownloadService _downloadService;
- private readonly IServiceProvider _serviceProvider;
+ private readonly IHttpContextAccessor _httpContextAccessor;
private readonly TaxSettings _taxSettings;
private readonly LoyaltyPointsSettings _loyaltyPointsSettings;
@@ -93,7 +94,7 @@ namespace Grand.Web.Admin.Services
ISalesEmployeeService salesEmployeeService,
ICustomerNoteService customerNoteService,
IDownloadService downloadService,
- IServiceProvider serviceProvider,
+ IHttpContextAccessor httpContextAccessor,
CustomerSettings customerSettings,
TaxSettings taxSettings,
LoyaltyPointsSettings loyaltyPointsSettings,
@@ -127,7 +128,7 @@ namespace Grand.Web.Admin.Services
_salesEmployeeService = salesEmployeeService;
_customerNoteService = customerNoteService;
_downloadService = downloadService;
- _serviceProvider = serviceProvider;
+ _httpContextAccessor = httpContextAccessor;
}
#region Utilities
@@ -213,7 +214,7 @@ namespace Grand.Web.Admin.Services
{
if (customer == null)
throw new ArgumentNullException(nameof(customer));
- var openAuthenticationService = _serviceProvider.GetRequiredService<IExternalAuthenticationService>();
+ var openAuthenticationService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IExternalAuthenticationService>();
var result = new List<CustomerModel.AssociatedExternalAuthModel>();
foreach (var record in await openAuthenticationService.GetExternalIdentifiers(customer))
{
@@ -249,7 +250,7 @@ namespace Grand.Web.Admin.Services
};
}
- protected virtual async Task PrepareSelesEmployeeModel(CustomerModel model)
+ protected virtual async Task PrepareSalesEmployeeModel(CustomerModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
@@ -504,20 +505,13 @@ namespace Grand.Web.Admin.Services
model.UsernamesEnabled = _customerSettings.UsernamesEnabled;
model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames;
- if (customer != null)
- {
- model.DisplayVatNumber = _taxSettings.EuVatEnabled;
- }
- else
- {
- model.DisplayVatNumber = false;
- }
+ model.DisplayVatNumber = customer != null && _taxSettings.EuVatEnabled;
//stores
await PrepareStoresModel(model);
//employees
- await PrepareSelesEmployeeModel(model);
+ await PrepareSalesEmployeeModel(model);
//customer attributes
await PrepareCustomerAttributeModel(model, customer);
@@ -763,7 +757,7 @@ namespace Grand.Web.Admin.Services
{
if (!model.VatNumber.Equals(prevVatNumber, StringComparison.OrdinalIgnoreCase))
{
- var checkVatService = _serviceProvider.GetRequiredService<IVatService>();
+ var checkVatService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IVatService>();
await _userFieldService.SaveField(customer,
SystemCustomerFieldNames.VatNumberStatusId,
(int)(await checkVatService.GetVatNumberStatus(model.VatNumber)).status);
@@ -892,21 +886,17 @@ namespace Grand.Web.Admin.Services
{
var customers = new List<Customer>();
customers.AddRange(await _customerService.GetCustomersByIds(selectedIds.ToArray()));
- for (var i = 0; i < customers.Count; i++)
+ foreach (var customer in customers.Where(customer => customer.Id != _workContext.CurrentCustomer.Id))
{
- var customer = customers[i];
- if (customer.Id != _workContext.CurrentCustomer.Id)
- {
- await _customerService.DeleteCustomer(customer);
- }
+ await _customerService.DeleteCustomer(customer);
}
}
public async Task SendEmail(Customer customer, CustomerModel.SendEmailModel model)
{
- var emailAccountService = _serviceProvider.GetRequiredService<IEmailAccountService>();
- var emailAccountSettings = _serviceProvider.GetRequiredService<EmailAccountSettings>();
- var queuedEmailService = _serviceProvider.GetRequiredService<IQueuedEmailService>();
+ var emailAccountService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IEmailAccountService>();
+ var emailAccountSettings = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<EmailAccountSettings>();
+ var queuedEmailService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IQueuedEmailService>();
var emailAccount = await emailAccountService.GetEmailAccountById(emailAccountSettings.DefaultEmailAccountId) ??
(await emailAccountService.GetAllEmailAccounts()).FirstOrDefault();
@@ -1015,8 +1005,7 @@ namespace Grand.Web.Admin.Services
}
}
- if (model.Address == null)
- model.Address = new AddressModel();
+ model.Address ??= new AddressModel();
model.Address.NameEnabled = _addressSettings.NameEnabled;
model.Address.FirstNameEnabled = true;
@@ -1077,10 +1066,10 @@ namespace Grand.Web.Admin.Services
var items = new List<ShoppingCartItemModel>();
if (cart.Any())
{
- var taxService = _serviceProvider.GetRequiredService<ITaxService>();
- var priceCalculationService = _serviceProvider.GetRequiredService<IPricingService>();
- var priceFormatter = _serviceProvider.GetRequiredService<IPriceFormatter>();
- var productAttributeFormatter = _serviceProvider.GetRequiredService<IProductAttributeFormatter>();
+ var taxService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<ITaxService>();
+ var priceCalculationService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IPricingService>();
+ var priceFormatter = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IPriceFormatter>();
+ var productAttributeFormatter = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IProductAttributeFormatter>();
foreach (var sci in cart)
{
var store = await _storeService.GetStoreById(sci.StoreId);
@@ -1111,7 +1100,7 @@ namespace Grand.Web.Admin.Services
var cart = customer.ShoppingCartItems.FirstOrDefault(a => a.Id == id);
if (cart != null)
{
- await _serviceProvider.GetRequiredService<IShoppingCartService>()
+ await _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IShoppingCartService>()
.DeleteShoppingCartItem(customer, cart, ensureOnlyActiveCheckoutAttributes: true);
await _customerService.UpdateCustomerInAdminPanel(customer);
}
@@ -1122,7 +1111,7 @@ namespace Grand.Web.Admin.Services
var cart = customer.ShoppingCartItems.FirstOrDefault(a => a.Id == shoppingCartId);
if (cart != null)
{
- return await _serviceProvider.GetRequiredService<IShoppingCartService>()
+ return await _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IShoppingCartService>()
.UpdateShoppingCartItem(
customer,
shoppingCartId,
@@ -1258,7 +1247,7 @@ namespace Grand.Web.Admin.Services
}
public virtual async Task<(IEnumerable<ContactFormModel> contactFormModels, int totalCount)> PrepareContactFormModel(string customerId, int pageIndex, int pageSize)
{
- var contactUsService = _serviceProvider.GetRequiredService<IContactUsService>();
+ var contactUsService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IContactUsService>();
var contactform = await contactUsService.GetAllContactUs(storeId: "", vendorId: "", customerId: customerId, pageIndex: pageIndex - 1, pageSize: pageSize);
var items = new List<ContactFormModel>();
foreach (var x in contactform)
@@ -1275,12 +1264,12 @@ namespace Grand.Web.Admin.Services
}
public virtual async Task<(IEnumerable<CustomerModel.OutOfStockSubscriptionModel> outOfStockSubscriptionModels, int totalCount)> PrepareOutOfStockSubscriptionModel(string customerId, int pageIndex, int pageSize)
{
- var outOfStockSubscriptionService = _serviceProvider.GetRequiredService<IOutOfStockSubscriptionService>();
+ var outOfStockSubscriptionService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IOutOfStockSubscriptionService>();
var subscriptions = await outOfStockSubscriptionService.GetAllSubscriptionsByCustomerId(customerId, "", pageIndex - 1, pageSize);
var items = new List<CustomerModel.OutOfStockSubscriptionModel>();
if (subscriptions.Any())
{
- var productAttributeFormatter = _serviceProvider.GetRequiredService<IProductAttributeFormatter>();
+ var productAttributeFormatter = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IProductAttributeFormatter>();
foreach (var x in subscriptions)
{
var store = await _storeService.GetStoreById(x.StoreId);
@@ -1300,7 +1289,7 @@ namespace Grand.Web.Admin.Services
}
public virtual async Task<IList<CustomerModel.CustomerNote>> PrepareCustomerNoteList(string customerId)
{
- var downloadService = _serviceProvider.GetRequiredService<IDownloadService>();
+ var downloadService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IDownloadService>();
var customerNoteModels = new List<CustomerModel.CustomerNote>();
foreach (var customerNote in (await _customerNoteService.GetCustomerNotes(customerId))
.OrderByDescending(on => on.CreatedOnUtc))
@@ -1335,7 +1324,7 @@ namespace Grand.Web.Admin.Services
if (displayToCustomer)
{
//email
- var messageProviderService = _serviceProvider.GetRequiredService<IMessageProviderService>();
+ var messageProviderService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IMessageProviderService>();
await messageProviderService.SendNewCustomerNoteMessage(customerNote,
await _customerService.GetCustomerById(customerId), _workContext.CurrentStore, _workContext.WorkingLanguage.Id);
diff --git a/src/Web/Grand.Web.Admin/Services/NewsViewModelService.cs b/src/Web/Grand.Web.Admin/Services/NewsViewModelService.cs
index b6c0b6ca2..0f9455bd2 100644
--- a/src/Web/Grand.Web.Admin/Services/NewsViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/NewsViewModelService.cs
@@ -13,6 +13,7 @@ using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Extensions.Mapping;
using Grand.Web.Admin.Interfaces;
using Grand.Web.Admin.Models.News;
+using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace Grand.Web.Admin.Services
@@ -26,7 +27,9 @@ namespace Grand.Web.Admin.Services
private readonly ITranslationService _translationService;
private readonly ISlugService _slugService;
private readonly IPictureService _pictureService;
- private readonly IServiceProvider _serviceProvider;
+ private readonly ILanguageService _languageService;
+ private readonly ICustomerService _customerService;
+ private readonly SeoSettings _seoSettings;
#endregion
#region Constructors
@@ -36,14 +39,18 @@ namespace Grand.Web.Admin.Services
ITranslationService translationService,
ISlugService slugService,
IPictureService pictureService,
- IServiceProvider serviceProvider)
+ ILanguageService languageService,
+ ICustomerService customerService,
+ SeoSettings seoSettings)
{
_newsService = newsService;
_dateTimeService = dateTimeService;
_translationService = translationService;
_slugService = slugService;
_pictureService = pictureService;
- _serviceProvider = serviceProvider;
+ _languageService = languageService;
+ _customerService = customerService;
+ _seoSettings = seoSettings;
}
#endregion
@@ -62,14 +69,13 @@ namespace Grand.Web.Admin.Services
}
public virtual async Task<NewsItem> InsertNewsItemModel(NewsItemModel model)
{
- var datetimeService = _serviceProvider.GetRequiredService<IDateTimeService>();
- var newsItem = model.ToEntity(datetimeService);
+ var newsItem = model.ToEntity(_dateTimeService);
newsItem.CreatedOnUtc = DateTime.UtcNow;
await _newsService.InsertNews(newsItem);
- var seName = await newsItem.ValidateSeName(model.SeName, model.Title, true, _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _serviceProvider.GetRequiredService<ILanguageService>());
+ var seName = await newsItem.ValidateSeName(model.SeName, model.Title, true, _seoSettings, _slugService, _languageService);
newsItem.SeName = seName;
- newsItem.Locales = await model.Locales.ToTranslationProperty(newsItem, x => x.Title, _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _serviceProvider.GetRequiredService<ILanguageService>());
+ newsItem.Locales = await model.Locales.ToTranslationProperty(newsItem, x => x.Title, _seoSettings, _slugService, _languageService);
await _newsService.UpdateNews(newsItem);
//search engine name
await _slugService.SaveSlug(newsItem, seName, "");
@@ -82,9 +88,9 @@ namespace Grand.Web.Admin.Services
{
var prevPictureId = newsItem.PictureId;
newsItem = model.ToEntity(newsItem, _dateTimeService);
- var seName = await newsItem.ValidateSeName(model.SeName, model.Title, true, _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _serviceProvider.GetRequiredService<ILanguageService>());
+ var seName = await newsItem.ValidateSeName(model.SeName, model.Title, true, _seoSettings, _slugService, _languageService);
newsItem.SeName = seName;
- newsItem.Locales = await model.Locales.ToTranslationProperty(newsItem, x => x.Title, _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _serviceProvider.GetRequiredService<ILanguageService>());
+ newsItem.Locales = await model.Locales.ToTranslationProperty(newsItem, x => x.Title, _seoSettings, _slugService, _languageService);
await _newsService.UpdateNews(newsItem);
//search engine name
@@ -116,7 +122,6 @@ namespace Grand.Web.Admin.Services
//load all news comments
comments = await _newsService.GetAllComments("");
}
- var customerService = _serviceProvider.GetRequiredService<ICustomerService>();
var items = new List<NewsCommentModel>();
foreach (var newsComment in comments.PagedForCommand(pageIndex, pageSize))
{
@@ -127,7 +132,7 @@ namespace Grand.Web.Admin.Services
NewsItemTitle = (await _newsService.GetNewsById(newsComment.NewsItemId))?.Title,
CustomerId = newsComment.CustomerId
};
- var customer = await customerService.GetCustomerById(newsComment.CustomerId);
+ var customer = await _customerService.GetCustomerById(newsComment.CustomerId);
commentModel.CustomerInfo = !string.IsNullOrEmpty(customer.Email) ? customer.Email : _translationService.GetResource("Admin.Customers.Guest");
commentModel.CreatedOn = _dateTimeService.ConvertToUserTime(newsComment.CreatedOnUtc, DateTimeKind.Utc);
commentModel.CommentTitle = newsComment.CommentTitle;
diff --git a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
index 4db5f95dc..5e6d70eec 100644
--- a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
@@ -30,7 +30,6 @@ using Grand.Web.Admin.Models.Orders;
using Grand.Web.Common.Extensions;
using MediatR;
using Microsoft.AspNetCore.Mvc.Rendering;
-using Microsoft.Extensions.DependencyInjection;
using System.Net;
namespace Grand.Web.Admin.Services
@@ -46,7 +45,6 @@ namespace Grand.Web.Admin.Services
private readonly IDiscountService _discountService;
private readonly ITranslationService _translationService;
private readonly IWorkContext _workContext;
- private readonly IGroupService _groupService;
private readonly ICurrencyService _currencyService;
private readonly IPaymentService _paymentService;
private readonly IPaymentTransactionService _paymentTransactionService;
@@ -67,7 +65,7 @@ namespace Grand.Web.Admin.Services
private readonly IMerchandiseReturnService _merchandiseReturnService;
private readonly ICustomerService _customerService;
private readonly IWarehouseService _warehouseService;
- private readonly IServiceProvider _serviceProvider;
+ private readonly IProductAttributeFormatter _productAttributeFormatter;
private readonly IShoppingCartValidator _shoppingCartValidator;
private readonly CurrencySettings _currencySettings;
private readonly TaxSettings _taxSettings;
@@ -87,7 +85,6 @@ namespace Grand.Web.Admin.Services
IDiscountService discountService,
ITranslationService translationService,
IWorkContext workContext,
- IGroupService groupService,
ICurrencyService currencyService,
IPaymentService paymentService,
IPaymentTransactionService paymentTransactionService,
@@ -108,14 +105,14 @@ namespace Grand.Web.Admin.Services
IMerchandiseReturnService merchandiseReturnService,
ICustomerService customerService,
IWarehouseService warehouseService,
- IServiceProvider serviceProvider,
IShoppingCartValidator shoppingCartValidator,
CurrencySettings currencySettings,
TaxSettings taxSettings,
AddressSettings addressSettings,
IOrderTagService orderTagService,
IOrderStatusService orderStatusService,
- IMediator mediator)
+ IMediator mediator,
+ IProductAttributeFormatter productAttributeFormatter)
{
_orderService = orderService;
_pricingService = priceCalculationService;
@@ -124,7 +121,6 @@ namespace Grand.Web.Admin.Services
_discountService = discountService;
_translationService = translationService;
_workContext = workContext;
- _groupService = groupService;
_currencyService = currencyService;
_paymentService = paymentService;
_paymentTransactionService = paymentTransactionService;
@@ -144,7 +140,6 @@ namespace Grand.Web.Admin.Services
_taxService = taxService;
_merchandiseReturnService = merchandiseReturnService;
_warehouseService = warehouseService;
- _serviceProvider = serviceProvider;
_shoppingCartValidator = shoppingCartValidator;
_currencySettings = currencySettings;
_taxSettings = taxSettings;
@@ -153,6 +148,7 @@ namespace Grand.Web.Admin.Services
_orderTagService = orderTagService;
_orderStatusService = orderStatusService;
_mediator = mediator;
+ _productAttributeFormatter = productAttributeFormatter;
}
#endregion
@@ -690,7 +686,7 @@ namespace Grand.Web.Admin.Services
model.ShippingAddress.NoteEnabled = _addressSettings.NoteEnabled;
model.ShippingAddressGoogleMapsUrl =
- $"http://maps.google.com/maps?f=q&hl=en&ie=UTF8&oe=UTF8&geocode=&q={WebUtility.UrlEncode(order.ShippingAddress.Address1 + " " + order.ShippingAddress.ZipPostalCode + " " + order.ShippingAddress.City + " " + (!string.IsNullOrEmpty(order.ShippingAddress.CountryId) ? (await _countryService.GetCountryById(order.ShippingAddress.CountryId))?.Name : ""))}";
+ $"https://maps.google.com/maps?f=q&hl=en&ie=UTF8&oe=UTF8&geocode=&q={WebUtility.UrlEncode(order.ShippingAddress.Address1 + " " + order.ShippingAddress.ZipPostalCode + " " + order.ShippingAddress.City + " " + (!string.IsNullOrEmpty(order.ShippingAddress.CountryId) ? (await _countryService.GetCountryById(order.ShippingAddress.CountryId))?.Name : ""))}";
}
}
else
@@ -1189,11 +1185,8 @@ namespace Grand.Web.Admin.Services
shoppingCartItem));
if (warnings.Count == 0)
{
- //no errors
- var productAttributeFormatter = _serviceProvider.GetRequiredService<IProductAttributeFormatter>();
- //attributes
var attributeDescription =
- await productAttributeFormatter.FormatAttributes(product, customattributes, customer);
+ await _productAttributeFormatter.FormatAttributes(product, customattributes, customer);
//save item
var orderItem = new OrderItem {
diff --git a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs
index a0eb90678..e02b60a5d 100644
--- a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs
@@ -6,7 +6,6 @@ using Grand.Business.Core.Interfaces.Catalog.Discounts;
using Grand.Business.Core.Interfaces.Catalog.Prices;
using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Catalog.Tax;
-using Grand.Business.Core.Interfaces.Checkout.Orders;
using Grand.Business.Core.Interfaces.Checkout.Shipping;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
@@ -29,9 +28,7 @@ using Grand.Web.Admin.Extensions.Mapping;
using Grand.Web.Admin.Interfaces;
using Grand.Web.Admin.Models.Catalog;
using Grand.Web.Common.Extensions;
-using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Rendering;
-using Microsoft.Extensions.DependencyInjection;
namespace Grand.Web.Admin.Services
{
@@ -67,10 +64,12 @@ namespace Grand.Web.Admin.Services
private readonly IStockQuantityService _stockQuantityService;
private readonly ILanguageService _languageService;
private readonly IProductAttributeFormatter _productAttributeFormatter;
- private readonly IServiceProvider _serviceProvider;
+ private readonly IAuctionService _auctionService;
+ private readonly IPriceFormatter _priceFormatter;
private readonly CurrencySettings _currencySettings;
private readonly MeasureSettings _measureSettings;
private readonly TaxSettings _taxSettings;
+ private readonly SeoSettings _seoSettings;
public ProductViewModelService(
IProductService productService,
@@ -103,10 +102,12 @@ namespace Grand.Web.Admin.Services
ILanguageService languageService,
IProductAttributeFormatter productAttributeFormatter,
IStockQuantityService stockQuantityService,
- IServiceProvider serviceProvider,
CurrencySettings currencySettings,
MeasureSettings measureSettings,
- TaxSettings taxSettings)
+ TaxSettings taxSettings,
+ SeoSettings seoSettings,
+ IAuctionService auctionService,
+ IPriceFormatter priceFormatter)
{
_productService = productService;
_inventoryManageService = inventoryManageService;
@@ -138,10 +139,12 @@ namespace Grand.Web.Admin.Services
_stockQuantityService = stockQuantityService;
_languageService = languageService;
_productAttributeFormatter = productAttributeFormatter;
- _serviceProvider = serviceProvider;
_currencySettings = currencySettings;
_measureSettings = measureSettings;
_taxSettings = taxSettings;
+ _seoSettings = seoSettings;
+ _auctionService = auctionService;
+ _priceFormatter = priceFormatter;
}
protected virtual async Task UpdatePictureSeoNames(Product product)
{
@@ -209,7 +212,6 @@ namespace Grand.Web.Admin.Services
await _productTagService.DetachProductTag(productTag, product.Id);
}
}
- var seoSettings = _serviceProvider.GetRequiredService<SeoSettings>();
foreach (var productTagName in productTags)
{
ProductTag productTag;
@@ -219,7 +221,7 @@ namespace Grand.Web.Admin.Services
//add new product tag
productTag = new ProductTag {
Name = productTagName,
- SeName = SeoExtensions.GetSeName(productTagName, seoSettings.ConvertNonWesternChars, seoSettings.AllowUnicodeCharsInUrls, seoSettings.SeoCharConversion),
+ SeName = SeoExtensions.GetSeName(productTagName, _seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls, _seoSettings.SeoCharConversion),
Count = 0
};
await _productTagService.InsertProductTag(productTag);
@@ -867,9 +869,9 @@ namespace Grand.Web.Admin.Services
await _productService.InsertProduct(product);
- model.SeName = await product.ValidateSeName(model.SeName, product.Name, true, _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _languageService);
+ model.SeName = await product.ValidateSeName(model.SeName, product.Name, true, _seoSettings, _slugService, _languageService);
product.SeName = model.SeName;
- product.Locales = await model.Locales.ToTranslationProperty(product, x => x.Name, _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _languageService);
+ product.Locales = await model.Locales.ToTranslationProperty(product, x => x.Name, _seoSettings, _slugService, _languageService);
//search engine name
await _slugService.SaveSlug(product, model.SeName, "");
@@ -909,9 +911,9 @@ namespace Grand.Web.Admin.Services
product = model.ToEntity(product, _dateTimeService);
product.UpdatedOnUtc = DateTime.UtcNow;
product.AutoAddRequiredProducts = model.AutoAddRequiredProducts;
- model.SeName = await product.ValidateSeName(model.SeName, product.Name, true, _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _languageService);
+ model.SeName = await product.ValidateSeName(model.SeName, product.Name, true, _seoSettings, _slugService, _languageService);
product.SeName = model.SeName;
- product.Locales = await model.Locales.ToTranslationProperty(product, x => x.Name, _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _languageService);
+ product.Locales = await model.Locales.ToTranslationProperty(product, x => x.Name, _seoSettings, _slugService, _languageService);
//search engine name
await _slugService.SaveSlug(product, model.SeName, "");
@@ -1527,16 +1529,14 @@ namespace Grand.Web.Admin.Services
}
public virtual async Task<(IEnumerable<ProductModel.BidModel> bidModels, int totalCount)> PrepareBidMode(string productId, int pageIndex, int pageSize)
{
- var auctionService = _serviceProvider.GetRequiredService<IAuctionService>();
- var priceFormatter = _serviceProvider.GetRequiredService<IPriceFormatter>();
- var bids = await auctionService.GetBidsByProductId(productId, pageIndex - 1, pageSize);
+ var bids = await _auctionService.GetBidsByProductId(productId, pageIndex - 1, pageSize);
var bidsModel = new List<ProductModel.BidModel>();
foreach (var x in bids)
{
bidsModel.Add(new ProductModel.BidModel {
BidId = x.Id,
ProductId = x.ProductId,
- Amount = priceFormatter.FormatPrice(x.Amount),
+ Amount = _priceFormatter.FormatPrice(x.Amount),
Date = _dateTimeService.ConvertToUserTime(x.Date, DateTimeKind.Utc),
CustomerId = x.CustomerId,
Email = (await _customerService.GetCustomerById(x.CustomerId))?.Email,
@@ -2020,9 +2020,7 @@ namespace Grand.Web.Admin.Services
}
public virtual async Task<IList<ProductModel.ProductAttributeCombinationModel>> PrepareProductAttributeCombinationModel(Product product)
{
- _serviceProvider.GetRequiredService<IShoppingCartService>();
var items = new List<ProductModel.ProductAttributeCombinationModel>();
-
foreach (var x in product.ProductAttributeCombinations)
{
var attributes = await _productAttributeFormatter.FormatAttributes(product, x.Attributes, _workContext.CurrentCustomer, "<br />", true, true, true, false, true, true);
diff --git a/src/Web/Grand.Web.Vendor/Services/MerchandiseReturnViewModelService.cs b/src/Web/Grand.Web.Vendor/Services/MerchandiseReturnViewModelService.cs
index 6cf9c2412..e62de9090 100644
--- a/src/Web/Grand.Web.Vendor/Services/MerchandiseReturnViewModelService.cs
+++ b/src/Web/Grand.Web.Vendor/Services/MerchandiseReturnViewModelService.cs
@@ -17,7 +17,6 @@ using Grand.Web.Vendor.Interfaces;
using Grand.Web.Vendor.Models.Common;
using Grand.Web.Vendor.Models.MerchandiseReturn;
using Microsoft.AspNetCore.Mvc.Rendering;
-using Microsoft.AspNetCore.Http;
namespace Grand.Web.Vendor.Services
{
@@ -40,26 +39,27 @@ namespace Grand.Web.Vendor.Services
private readonly ICountryService _countryService;
private readonly IAddressAttributeService _addressAttributeService;
private readonly IAddressAttributeParser _addressAttributeParser;
- private readonly IHttpContextAccessor _httpContextAccessor;
- #endregion Fields
+ #endregion Fields
#region Constructors
- public MerchandiseReturnViewModelService(IOrderService orderService,
+ public MerchandiseReturnViewModelService(
+ IOrderService orderService,
IWorkContext workContext,
IProductService productService,
- ICustomerService customerService, IDateTimeService dateTimeService,
+ ICustomerService customerService,
+ IDateTimeService dateTimeService,
ITranslationService translationService,
- IMessageProviderService messageProviderService, LanguageSettings languageSettings,
+ IMessageProviderService messageProviderService,
+ LanguageSettings languageSettings,
IMerchandiseReturnService merchandiseReturnService,
IPriceFormatter priceFormatter,
AddressSettings addressSettings,
ICountryService countryService,
IAddressAttributeService addressAttributeService,
IAddressAttributeParser addressAttributeParser,
- OrderSettings orderSettings,
- IHttpContextAccessor httpContextAccessor)
+ OrderSettings orderSettings)
{
_orderService = orderService;
_workContext = workContext;
@@ -76,7 +76,6 @@ namespace Grand.Web.Vendor.Services
_addressAttributeService = addressAttributeService;
_addressAttributeParser = addressAttributeParser;
_orderSettings = orderSettings;
- _httpContextAccessor = httpContextAccessor;
}
#endregion
diff --git a/src/Web/Grand.Web.Vendor/Services/ProductViewModelService.cs b/src/Web/Grand.Web.Vendor/Services/ProductViewModelService.cs
index a1b0b6727..ad8a6bb23 100644
--- a/src/Web/Grand.Web.Vendor/Services/ProductViewModelService.cs
+++ b/src/Web/Grand.Web.Vendor/Services/ProductViewModelService.cs
@@ -5,7 +5,6 @@ using Grand.Business.Core.Interfaces.Catalog.Directory;
using Grand.Business.Core.Interfaces.Catalog.Prices;
using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Catalog.Tax;
-using Grand.Business.Core.Interfaces.Checkout.Orders;
using Grand.Business.Core.Interfaces.Checkout.Shipping;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
@@ -27,7 +26,6 @@ using Grand.Web.Vendor.Models.Catalog;
using Grand.Web.Common.Extensions;
using Grand.Web.Vendor.Extensions;
using Microsoft.AspNetCore.Mvc.Rendering;
-using Microsoft.Extensions.DependencyInjection;
namespace Grand.Web.Vendor.Services
{
@@ -58,11 +56,12 @@ namespace Grand.Web.Vendor.Services
private readonly IStockQuantityService _stockQuantityService;
private readonly ILanguageService _languageService;
private readonly IProductAttributeFormatter _productAttributeFormatter;
- private readonly IServiceProvider _serviceProvider;
+ private readonly IAuctionService _auctionService;
+ private readonly IPriceFormatter _priceFormatter;
private readonly CurrencySettings _currencySettings;
private readonly MeasureSettings _measureSettings;
private readonly TaxSettings _taxSettings;
-
+ private readonly SeoSettings _seoSettings;
public ProductViewModelService(
IProductService productService,
IInventoryManageService inventoryManageService,
@@ -89,10 +88,11 @@ namespace Grand.Web.Vendor.Services
ILanguageService languageService,
IProductAttributeFormatter productAttributeFormatter,
IStockQuantityService stockQuantityService,
- IServiceProvider serviceProvider,
+ IAuctionService auctionService,
+ IPriceFormatter priceFormatter,
CurrencySettings currencySettings,
MeasureSettings measureSettings,
- TaxSettings taxSettings)
+ TaxSettings taxSettings, SeoSettings seoSettings)
{
_productService = productService;
_inventoryManageService = inventoryManageService;
@@ -119,10 +119,12 @@ namespace Grand.Web.Vendor.Services
_stockQuantityService = stockQuantityService;
_languageService = languageService;
_productAttributeFormatter = productAttributeFormatter;
- _serviceProvider = serviceProvider;
+ _auctionService = auctionService;
+ _priceFormatter = priceFormatter;
_currencySettings = currencySettings;
_measureSettings = measureSettings;
_taxSettings = taxSettings;
+ _seoSettings = seoSettings;
}
protected virtual async Task UpdatePictureSeoNames(Product product)
@@ -762,11 +764,10 @@ namespace Grand.Web.Vendor.Services
product.VendorId = _workContext.CurrentVendor!.Id;
await _productService.InsertProduct(product);
- model.SeName = await product.ValidateSeName(model.SeName, product.Name, true,
- _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _languageService);
+ model.SeName = await product.ValidateSeName(model.SeName, product.Name, true, _seoSettings, _slugService, _languageService);
product.SeName = model.SeName;
product.Locales = await model.Locales.ToTranslationProperty(product, x => x.Name,
- _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _languageService);
+ _seoSettings, _slugService, _languageService);
//search engine name
await _slugService.SaveSlug(product, model.SeName, "");
@@ -790,11 +791,9 @@ namespace Grand.Web.Vendor.Services
product = model.ToEntity(product, _dateTimeService);
product.UpdatedOnUtc = DateTime.UtcNow;
product.AutoAddRequiredProducts = model.AutoAddRequiredProducts;
- model.SeName = await product.ValidateSeName(model.SeName, product.Name, true,
- _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _languageService);
+ model.SeName = await product.ValidateSeName(model.SeName, product.Name, true, _seoSettings, _slugService, _languageService);
product.SeName = model.SeName;
- product.Locales = await model.Locales.ToTranslationProperty(product, x => x.Name,
- _serviceProvider.GetRequiredService<SeoSettings>(), _slugService, _languageService);
+ product.Locales = await model.Locales.ToTranslationProperty(product, x => x.Name, _seoSettings, _slugService, _languageService);
//search engine name
await _slugService.SaveSlug(product, model.SeName, "");
@@ -1333,16 +1332,14 @@ namespace Grand.Web.Vendor.Services
public virtual async Task<(IEnumerable<ProductModel.BidModel> bidModels, int totalCount)> PrepareBidMode(
string productId, int pageIndex, int pageSize)
{
- var auctionService = _serviceProvider.GetRequiredService<IAuctionService>();
- var priceFormatter = _serviceProvider.GetRequiredService<IPriceFormatter>();
- var bids = await auctionService.GetBidsByProductId(productId, pageIndex - 1, pageSize);
+ var bids = await _auctionService.GetBidsByProductId(productId, pageIndex - 1, pageSize);
var bidsModel = new List<ProductModel.BidModel>();
foreach (var x in bids)
{
bidsModel.Add(new ProductModel.BidModel {
BidId = x.Id,
ProductId = x.ProductId,
- Amount = priceFormatter.FormatPrice(x.Amount),
+ Amount = _priceFormatter.FormatPrice(x.Amount),
Date = _dateTimeService.ConvertToUserTime(x.Date, DateTimeKind.Utc),
CustomerId = x.CustomerId,
Email = (await _customerService.GetCustomerById(x.CustomerId))?.Email,
@@ -1888,7 +1885,6 @@ namespace Grand.Web.Vendor.Services
public virtual async Task<IList<ProductModel.ProductAttributeCombinationModel>>
PrepareProductAttributeCombinationModel(Product product)
{
- _serviceProvider.GetRequiredService<IShoppingCartService>();
var items = new List<ProductModel.ProductAttributeCombinationModel>();
foreach (var x in product.ProductAttributeCombinations)