withSIX.Mini.Infra.Data.Services.DbContextScope.SetAmbientScope C# (CSharp) Method

SetAmbientScope() static private method

Makes the provided 'dbContextScope' available as the the ambient scope via the CallContext.
static private SetAmbientScope ( DbContextScope newAmbientScope ) : void
newAmbientScope DbContextScope
return void
        internal static void SetAmbientScope(DbContextScope newAmbientScope) {
            if (newAmbientScope == null)
                throw new ArgumentNullException(nameof(newAmbientScope));

            var current = GetIdentifier();

            var id = newAmbientScope._instanceIdentifier;
            if (current == id)
                return;

            // Store the new scope's instance identifier in the CallContext, making it the ambient scope
            SetId(id);

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

Usage Example

Esempio n. 1
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            if (_savedScope != null)
            {
                DbContextScope.SetAmbientScope(_savedScope);
                _savedScope = null;
            }

            _disposed = true;
        }