using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace Pole.Orleans.Provider.EntityframeworkCore { public static class GrainStorageContext where TEntity : class { // ReSharper disable once StaticMemberInGenericType private static readonly AsyncLocal IsConfiguredLocal = new AsyncLocal(); private static readonly AsyncLocal> ConfigureStateDelegateLocal = new AsyncLocal>(); internal static bool IsConfigured => IsConfiguredLocal.Value; internal static ConfigureEntryStateDelegate ConfigureStateDelegate => ConfigureStateDelegateLocal.Value; /// /// Configures the entry state. /// Use it to modify what gets changed during the write operations. /// /// The delegate to be called before saving context's state. public static void ConfigureEntryState(ConfigureEntryStateDelegate configureState) { ConfigureStateDelegateLocal.Value = configureState; IsConfiguredLocal.Value = true; } public static void Clear() { ConfigureStateDelegateLocal.Value = null; IsConfiguredLocal.Value = false; } } }