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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
InstallationService - remove IHttpContextAccessor
KrzysztofPajakeb8eb71d97ed
diff --git a/src/Business/Grand.Business.System/Interfaces/Installation/IInstallationService.cs b/src/Business/Grand.Business.System/Interfaces/Installation/IInstallationService.csindex 1ce89121f..c288154c6 100644--- a/src/Business/Grand.Business.System/Interfaces/Installation/IInstallationService.cs+++ b/src/Business/Grand.Business.System/Interfaces/Installation/IInstallationService.cs@@ -1,9 +1,13 @@+using Microsoft.AspNetCore.Http;using System.Threading.Tasks;namespace Grand.Business.System.Interfaces.Installation{public partial interface IInstallationService{- Task InstallData(string defaultUserEmail, string defaultUserPassword, string collation, bool installSampleData = true, string companyName = "", string companyAddress = "", string companyPhoneNumber = "", string companyEmail = "");+ Task InstallData(+ string httpscheme, HostString host,+ string defaultUserEmail, string defaultUserPassword, string collation, bool installSampleData = true,+ string companyName = "", string companyAddress = "", string companyPhoneNumber = "", string companyEmail = "");}}diff --git a/src/Business/Grand.Business.System/Services/Installation/InstallDataStores.cs b/src/Business/Grand.Business.System/Services/Installation/InstallDataStores.csindex b92244b64..1b72a6adb 100644--- a/src/Business/Grand.Business.System/Services/Installation/InstallDataStores.cs+++ b/src/Business/Grand.Business.System/Services/Installation/InstallDataStores.cs@@ -1,7 +1,6 @@using Grand.Business.System.Interfaces.Installation;using Grand.Domain.Stores;using Microsoft.AspNetCore.Http;-using Microsoft.Extensions.DependencyInjection;using System.Collections.Generic;using System.Threading.Tasks;@@ -9,18 +8,19 @@ namespace Grand.Business.System.Services.Installation{public partial class InstallationService : IInstallationService{- protected virtual async Task InstallStores(string companyName, string companyAddress, string companyPhoneNumber, string companyEmail)+ protected virtual async Task InstallStores(+ string httpscheme, HostString host,+ string companyName, string companyAddress, string companyPhoneNumber, string companyEmail){- var httpContextAccessor = _serviceProvider.GetRequiredService<IHttpContextAccessor>();- var storeUrl = $"{httpContextAccessor.HttpContext?.Request?.Scheme}://{httpContextAccessor.HttpContext?.Request?.Host}";var stores = new List<Store>{new Store{Name = "Your store name",Shortcut = "Store",- Url = storeUrl,- SslEnabled = false,+ Url = $"http://{host}",+ SecureUrl = $"https://{host}",+ SslEnabled = httpscheme.ToLowerInvariant() == "https" ? true : false,DisplayOrder = 1,CompanyName = companyName,CompanyAddress = companyAddress,@@ -29,7 +29,7 @@ namespace Grand.Business.System.Services.InstallationCompanyVat = null,CompanyEmail = companyEmail,CompanyHours = "Monday - Sunday / 8:00AM - 6:00PM",- Domains = new List<DomainHost>(){ new DomainHost() { HostName = httpContextAccessor.HttpContext?.Request?.Host.Host, Url = storeUrl, Primary = true } }+ Domains = new List<DomainHost>(){ new DomainHost() { HostName = host.Host, Url = $"{httpscheme}://{host}", Primary = true } }},};diff --git a/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs b/src/Business/Grand.Business.System/Services/Installation/InstallationService.csindex aaa1c413a..3ad1f6727 100644--- a/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs+++ b/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs@@ -35,6 +35,7 @@ using Grand.Infrastructure;using Grand.Infrastructure.TypeSearchers;using Grand.SharedKernel;using Microsoft.AspNetCore.Hosting;+using Microsoft.AspNetCore.Http;using Microsoft.Extensions.DependencyInjection;using System;using System.IO;@@ -677,7 +678,7 @@ namespace Grand.Business.System.Services.Installation#region Methods- public virtual async Task InstallData(string defaultUserEmail,+ public virtual async Task InstallData(string httpscheme, HostString host, string defaultUserEmail,string defaultUserPassword, string collation, bool installSampleData = true, string companyName = "", string companyAddress = "",string companyPhoneNumber = "", string companyEmail = ""){@@ -686,7 +687,7 @@ namespace Grand.Business.System.Services.Installationawait CreateTables(collation);await InstallVersion();await InstallMenuAdminSiteMap();- await InstallStores(companyName, companyAddress, companyPhoneNumber, companyEmail);+ await InstallStores(httpscheme, host, companyName, companyAddress, companyPhoneNumber, companyEmail);await InstallMeasures();await InstallTaxCategories();await InstallLanguages();diff --git a/src/Web/Grand.Web/Controllers/InstallController.cs b/src/Web/Grand.Web/Controllers/InstallController.csindex 90cb46e7c..bceb71e0f 100644--- a/src/Web/Grand.Web/Controllers/InstallController.cs+++ b/src/Web/Grand.Web/Controllers/InstallController.cs@@ -210,7 +210,9 @@ namespace Grand.Web.Controllersawait DataSettingsManager.SaveSettings(settings);var installationService = _serviceProvider.GetRequiredService<IInstallationService>();- await installationService.InstallData(model.AdminEmail, model.AdminPassword, model.Collation,+ await installationService.InstallData(+ HttpContext.Request.Scheme, HttpContext.Request.Host,+ model.AdminEmail, model.AdminPassword, model.Collation,model.InstallSampleData, model.CompanyName, model.CompanyAddress, model.CompanyPhoneNumber, model.CompanyEmail);//reset cache