diff --git a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs index d0b86c94..f580f5f9 100644 --- a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs @@ -75,11 +75,16 @@ namespace Microsoft.Extensions.DependencyInjection return services; } + internal static IServiceCollection AddOqtaneServerScopedServices(this IServiceCollection services) + { + services.AddScoped(); + return services; + } + internal static IServiceCollection AddOqtaneTransientServices(this IServiceCollection services) { services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/Oqtane.Server/Infrastructure/SiteState.cs b/Oqtane.Server/Infrastructure/SiteState.cs new file mode 100644 index 00000000..d765f90d --- /dev/null +++ b/Oqtane.Server/Infrastructure/SiteState.cs @@ -0,0 +1,9 @@ +using Oqtane.Models; + +namespace Oqtane.Infrastructure +{ + public class SiteState + { + public Alias Alias { get; set; } + } +} diff --git a/Oqtane.Server/Infrastructure/TenantManager.cs b/Oqtane.Server/Infrastructure/TenantManager.cs index 616e4610..de3ca94e 100644 --- a/Oqtane.Server/Infrastructure/TenantManager.cs +++ b/Oqtane.Server/Infrastructure/TenantManager.cs @@ -3,7 +3,6 @@ using System.Linq; using Microsoft.AspNetCore.Http; using Oqtane.Models; using Oqtane.Repository; -using Oqtane.Shared; namespace Oqtane.Infrastructure { diff --git a/Oqtane.Server/Repository/SettingRepository.cs b/Oqtane.Server/Repository/SettingRepository.cs index 0003e35c..3b354dd2 100644 --- a/Oqtane.Server/Repository/SettingRepository.cs +++ b/Oqtane.Server/Repository/SettingRepository.cs @@ -12,14 +12,14 @@ namespace Oqtane.Repository { private TenantDBContext _tenant; private MasterDBContext _master; - private readonly Alias _alias; + private readonly ITenantManager _tenantManager; private readonly IMemoryCache _cache; public SettingRepository(TenantDBContext tenant, MasterDBContext master, ITenantManager tenantManager, IMemoryCache cache) { _tenant = tenant; _master = master; - _alias = tenantManager.GetAlias(); + _tenantManager = tenantManager; _cache = cache; } @@ -150,7 +150,7 @@ namespace Oqtane.Repository { if (EntityName == EntityNames.Site) { - _cache.Remove(Constants.HttpContextSiteSettingsKey + _alias.SiteKey); + _cache.Remove(Constants.HttpContextSiteSettingsKey + _tenantManager.GetAlias().SiteKey); } } } diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs index 2821e003..67bf7bd5 100644 --- a/Oqtane.Server/Startup.cs +++ b/Oqtane.Server/Startup.cs @@ -74,7 +74,8 @@ namespace Oqtane // register scoped core services services.AddScoped() - .AddOqtaneScopedServices(); + .AddOqtaneScopedServices() + .AddOqtaneServerScopedServices(); services.AddSingleton(); diff --git a/Oqtane.Shared/Shared/SiteState.cs b/Oqtane.Shared/Shared/SiteState.cs index 9a7320e3..2c51d6cd 100644 --- a/Oqtane.Shared/Shared/SiteState.cs +++ b/Oqtane.Shared/Shared/SiteState.cs @@ -2,11 +2,11 @@ using Oqtane.Models; namespace Oqtane.Shared { - // this class is used for passing state between components and services as well as controllers and repositories + // this class is used for passing state between components and services on the client public class SiteState { public Alias Alias { get; set; } - public string AntiForgeryToken { get; set; } // for use in client services - public string RemoteIPAddress { get; set; } // captured in _host as cannot be reliably retrieved on Blazor Server + public string AntiForgeryToken { get; set; } // passed from server for use in service calls on client + public string RemoteIPAddress { get; set; } // passed from server as cannot be reliable retrieved on client } }