Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

丁松杰 / Pole

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • Pole
  • src
  • Pole.Orleans.Provider.Entityframework...
  • GrainStorageContext.cs
Find file
BlameHistoryPermalink
  • 丁松杰's avatar
    添加 orleans.provider. entityframeworkcore 部分代码 · d827c767
    丁松杰 committed 5 years ago
    d827c767
GrainStorageContext.cs 1.43 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Pole.Orleans.Provider.EntityframeworkCore
{
    public static class GrainStorageContext<TEntity>
           where TEntity : class
    {
        // ReSharper disable once StaticMemberInGenericType
        private static readonly AsyncLocal<bool> IsConfiguredLocal
            = new AsyncLocal<bool>();

        private static readonly AsyncLocal<ConfigureEntryStateDelegate<TEntity>>
            ConfigureStateDelegateLocal
                = new AsyncLocal<ConfigureEntryStateDelegate<TEntity>>();

        internal static bool IsConfigured => IsConfiguredLocal.Value;

        internal static ConfigureEntryStateDelegate<TEntity> ConfigureStateDelegate
            => ConfigureStateDelegateLocal.Value;

        /// <summary>
        /// Configures the entry state. 
        /// Use it to modify what gets changed during the write operations.
        /// </summary>
        /// <param name="configureState">The delegate to be called before saving context's state.</param>
        public static void ConfigureEntryState(ConfigureEntryStateDelegate<TEntity> configureState)
        {
            ConfigureStateDelegateLocal.Value = configureState;
            IsConfiguredLocal.Value = true;
        }

        public static void Clear()
        {
            ConfigureStateDelegateLocal.Value = null;
            IsConfiguredLocal.Value = false;
        }
    }
}