Exemplo n.º 1
0
 public DbContextScope(ILocalCache cache, ISettingsStorage settingsStorage) {
     _parentScope = GetAmbientScope();
     _cache = cache;
     if (_parentScope == null) {
         _gameContext = new Lazy<IGameContext>(Factory);
         _settingsContext = new Lazy<ISettingsStorage>(() => settingsStorage);
         _contentLinkContext = new Lazy<IContentFolderLinkContext>(() => new ContentFolderLinkContext(Common.Paths.LocalDataPath.GetChildFileWithName("folderlink.json")));
     } else
         _nested = true;
     SetAmbientScope(this);
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Makes the provided 'dbContextScope' available as the the ambient scope via the CallContext.
        /// </summary>
        internal static void SetAmbientScope(DbContextScope newAmbientScope) {
            if (newAmbientScope == null)
                throw new ArgumentNullException("newAmbientScope");

            var current = CallContext.LogicalGetData(ambientDbContextScopeKey) as InstanceIdentifier;

            if (current == newAmbientScope._instanceIdentifier)
                return;

            // Store the new scope's instance identifier in the CallContext, making it the ambient scope
            CallContext.LogicalSetData(ambientDbContextScopeKey, newAmbientScope._instanceIdentifier);

            // Keep track of this instance (or do nothing if we're already tracking it)
            dbContextScopeInstances.GetValue(newAmbientScope._instanceIdentifier, key => newAmbientScope);
        }