mirror of https://github.com/abpframework/abp.git
11 changed files with 147 additions and 2 deletions
@ -0,0 +1,10 @@ |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Timing; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.MauiBlazor; |
|||
|
|||
[Dependency(ReplaceServices = true)] |
|||
public class MauiBlazorCurrentTimezoneProvider : ICurrentTimezoneProvider, ISingletonDependency |
|||
{ |
|||
public string? TimeZone { get; set; } |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Timing; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly; |
|||
|
|||
[Dependency(ReplaceServices = true)] |
|||
public class WebAssemblyCurrentTimezoneProvider : ICurrentTimezoneProvider, ISingletonDependency |
|||
{ |
|||
public string? TimeZone { get; set; } |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.AspNetCore.Middleware; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Settings; |
|||
using Volo.Abp.Timing; |
|||
|
|||
namespace Microsoft.AspNetCore.Timing; |
|||
|
|||
public class AbpTimeZoneMiddleware : AbpMiddlewareBase, ITransientDependency |
|||
{ |
|||
public async override Task InvokeAsync(HttpContext context, RequestDelegate next) |
|||
{ |
|||
var settingProvider = context.RequestServices.GetRequiredService<ISettingProvider>(); |
|||
var timezone = await settingProvider.GetOrNullAsync(TimingSettingNames.TimeZone); |
|||
if (timezone.IsNullOrEmpty()) |
|||
{ |
|||
await next(context); |
|||
return; |
|||
} |
|||
|
|||
var currentTimezoneProvider = context.RequestServices.GetRequiredService<ICurrentTimezoneProvider>(); |
|||
using (currentTimezoneProvider.Change(timezone)) |
|||
{ |
|||
await next(context); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using System.Threading; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Timing; |
|||
|
|||
public class CurrentTimezoneProvider : ICurrentTimezoneProvider, ISingletonDependency |
|||
{ |
|||
public string? TimeZone |
|||
{ |
|||
get => _currentScope.Value; |
|||
set => _currentScope.Value = value; |
|||
} |
|||
|
|||
private readonly AsyncLocal<string?> _currentScope; |
|||
|
|||
public CurrentTimezoneProvider() |
|||
{ |
|||
_currentScope = new AsyncLocal<string?>(); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.Timing; |
|||
|
|||
public static class CurrentTimezoneProviderExtensions |
|||
{ |
|||
public static IDisposable Change(this ICurrentTimezoneProvider currentTimezoneProvider, string? timeZone) |
|||
{ |
|||
var parentScope = currentTimezoneProvider.TimeZone; |
|||
currentTimezoneProvider.TimeZone = timeZone; |
|||
|
|||
return new DisposeAction<ValueTuple<ICurrentTimezoneProvider, string?>>(static (state) => |
|||
{ |
|||
var (currentTimezoneProvider, parentScope) = state; |
|||
currentTimezoneProvider.TimeZone = parentScope; |
|||
}, (currentTimezoneProvider, parentScope)); |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace Volo.Abp.Timing; |
|||
|
|||
public interface ICurrentTimezoneProvider |
|||
{ |
|||
string? TimeZone { get; set; } |
|||
} |
|||
Loading…
Reference in new issue