diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Aspects/AbpCrossCuttingConcerns.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Aspects/AbpCrossCuttingConcerns.cs index c137f1fc9c..9007b334b4 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Aspects/AbpCrossCuttingConcerns.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Aspects/AbpCrossCuttingConcerns.cs @@ -60,10 +60,11 @@ public static class AbpCrossCuttingConcerns public static IDisposable Applying(object obj, params string[] concerns) { AddApplied(obj, concerns); - return new DisposeAction(() => + return new DisposeAction>(static (state) => { + var (obj, concerns) = state; RemoveApplied(obj, concerns); - }); + }, (obj, concerns)); } public static string[] GetApplieds(object obj) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DisposeAction.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DisposeAction.cs index ba0b61eed7..0bb9cf46a8 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/DisposeAction.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/DisposeAction.cs @@ -5,7 +5,7 @@ namespace Volo.Abp; /// /// This class can be used to provide an action when -/// Dipose method is called. +/// Dispose method is called. /// public class DisposeAction : IDisposable { @@ -27,3 +27,34 @@ public class DisposeAction : IDisposable _action(); } } + +/// +/// This class can be used to provide an action when +/// Dispose method is called. +/// The type of the parameter of the action. +/// +public class DisposeAction : IDisposable +{ + private readonly Action _action; + + [CanBeNull] + private readonly T _parameter; + + /// + /// Creates a new object. + /// + /// Action to be executed when this object is disposed. + /// The parameter of the action. + public DisposeAction(Action action, T parameter) + { + Check.NotNull(action, nameof(action)); + + _action = action; + _parameter = parameter; + } + + public void Dispose() + { + _action(_parameter); + } +} diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/IO/DirectoryHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/IO/DirectoryHelper.cs index bb30087056..9743898496 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/IO/DirectoryHelper.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/IO/DirectoryHelper.cs @@ -83,6 +83,6 @@ public static class DirectoryHelper Directory.SetCurrentDirectory(targetDirectory); - return new DisposeAction(() => { Directory.SetCurrentDirectory(currentDirectory); }); + return new DisposeAction(Directory.SetCurrentDirectory, currentDirectory); } } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Localization/CultureHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Localization/CultureHelper.cs index adf2890b21..d2e15fdf25 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Localization/CultureHelper.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Localization/CultureHelper.cs @@ -29,11 +29,12 @@ public static class CultureHelper CultureInfo.CurrentCulture = culture; CultureInfo.CurrentUICulture = uiCulture ?? culture; - return new DisposeAction(() => + return new DisposeAction>(static (state) => { + var (currentCulture, currentUiCulture) = state; CultureInfo.CurrentCulture = currentCulture; CultureInfo.CurrentUICulture = currentUiCulture; - }); + }, (currentCulture, currentUiCulture)); } public static bool IsRtl => CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft; diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Threading/SemaphoreSlimExtensions.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Threading/SemaphoreSlimExtensions.cs index 79693a9acb..7eaed3821b 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Threading/SemaphoreSlimExtensions.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Threading/SemaphoreSlimExtensions.cs @@ -80,9 +80,9 @@ public static class SemaphoreSlimExtensions private static IDisposable GetDispose(this SemaphoreSlim semaphoreSlim) { - return new DisposeAction(() => + return new DisposeAction(static (semaphoreSlim) => { semaphoreSlim.Release(); - }); + }, semaphoreSlim); } } diff --git a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentTenant.cs b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentTenant.cs index a86ce2a40c..fb5d2b147c 100644 --- a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentTenant.cs +++ b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentTenant.cs @@ -27,9 +27,11 @@ public class CurrentTenant : ICurrentTenant, ITransientDependency { var parentScope = _currentTenantAccessor.Current; _currentTenantAccessor.Current = new BasicTenantInfo(tenantId, name); - return new DisposeAction(() => + + return new DisposeAction>(static (state) => { - _currentTenantAccessor.Current = parentScope; - }); + var (currentTenantAccessor, parentScope) = state; + currentTenantAccessor.Current = parentScope; + }, (_currentTenantAccessor, parentScope)); } } diff --git a/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/CurrentPrincipalAccessorBase.cs b/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/CurrentPrincipalAccessorBase.cs index 9c27fd166a..1d3e296e38 100644 --- a/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/CurrentPrincipalAccessorBase.cs +++ b/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/CurrentPrincipalAccessorBase.cs @@ -21,9 +21,11 @@ public abstract class CurrentPrincipalAccessorBase : ICurrentPrincipalAccessor { var parent = Principal; _currentPrincipal.Value = principal; - return new DisposeAction(() => + + return new DisposeAction, ClaimsPrincipal>>(static (state) => { - _currentPrincipal.Value = parent; - }); + var (currentPrincipal, parent) = state; + currentPrincipal.Value = parent; + }, (_currentPrincipal, parent)); } } diff --git a/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AmbientDataContextAmbientScopeProvider.cs b/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AmbientDataContextAmbientScopeProvider.cs index 7d5c81abb4..06b71d16f3 100644 --- a/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AmbientDataContextAmbientScopeProvider.cs +++ b/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AmbientDataContextAmbientScopeProvider.cs @@ -46,18 +46,21 @@ public class AmbientDataContextAmbientScopeProvider : IAmbientScopeProvider + return new DisposeAction, ScopeItem, IAmbientDataContext, string>>(static (state) => { - ScopeDictionary.TryRemove(item.Id, out item); + var (scopeDictionary, item, dataContext, contextKey) = state; + + scopeDictionary.TryRemove(item.Id, out item); if (item.Outer == null) { - _dataContext.SetData(contextKey, null); + dataContext.SetData(contextKey, null); return; } - _dataContext.SetData(contextKey, item.Outer.Id); - }); + dataContext.SetData(contextKey, item.Outer.Id); + + }, (ScopeDictionary, item, _dataContext, contextKey)); } private ScopeItem GetCurrentItem(string contextKey) diff --git a/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AsyncLocalSimpleScopeExtensions.cs b/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AsyncLocalSimpleScopeExtensions.cs index dd33bd1ba1..3d353921d9 100644 --- a/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AsyncLocalSimpleScopeExtensions.cs +++ b/framework/src/Volo.Abp.Threading/Volo/Abp/Threading/AsyncLocalSimpleScopeExtensions.cs @@ -9,9 +9,10 @@ public static class AsyncLocalSimpleScopeExtensions { var previousValue = asyncLocal.Value; asyncLocal.Value = value; - return new DisposeAction(() => + return new DisposeAction, T>>(static (state) => { + var (asyncLocal, previousValue) = state; asyncLocal.Value = previousValue; - }); + }, (asyncLocal, previousValue)); } }