cleanly separate SiteState service for client and server use cases
This commit is contained in:
parent
8b0b7492f5
commit
c8129607e8
|
@ -75,11 +75,16 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return services;
|
||||
}
|
||||
|
||||
internal static IServiceCollection AddOqtaneServerScopedServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<Oqtane.Infrastructure.SiteState>();
|
||||
return services;
|
||||
}
|
||||
|
||||
internal static IServiceCollection AddOqtaneTransientServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<ITenantManager, TenantManager>();
|
||||
services.AddTransient<IAliasAccessor, AliasAccessor>();
|
||||
|
||||
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
|
||||
services.AddTransient<IThemeRepository, ThemeRepository>();
|
||||
services.AddTransient<IUserPermissions, UserPermissions>();
|
||||
|
|
9
Oqtane.Server/Infrastructure/SiteState.cs
Normal file
9
Oqtane.Server/Infrastructure/SiteState.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
public class SiteState
|
||||
{
|
||||
public Alias Alias { get; set; }
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ using System.Linq;
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,8 @@ namespace Oqtane
|
|||
|
||||
// register scoped core services
|
||||
services.AddScoped<IAuthorizationHandler, PermissionHandler>()
|
||||
.AddOqtaneScopedServices();
|
||||
.AddOqtaneScopedServices()
|
||||
.AddOqtaneServerScopedServices();
|
||||
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user