Esempio n. 1
0
        // IDisposable implementation

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (isDisposed)
            {
                return;
            }
            try {
                OrmLog.Debug(Strings.LogSessionXDisposing, this);

                SystemEvents.NotifyDisposing();
                Events.NotifyDisposing();

                Services.DisposeSafely();
                Handler.DisposeSafely();
                CommandProcessorContextProvider.DisposeSafely();

                Domain.ReleaseSingleConnection();

                disposableSet.DisposeSafely();
                disposableSet = null;

                EntityChangeRegistry.Clear();
                EntitySetChangeRegistry.Clear();
                EntityStateCache.Clear();
                ReferenceFieldsChangesRegistry.Clear();
                NonPairedReferencesRegistry.Clear();
            }
            finally {
                isDisposed = true;
            }
        }
Esempio n. 2
0
        // Constructors

        internal Session(Domain domain, SessionConfiguration configuration, bool activate)
            : base(domain)
        {
            Guid = Guid.NewGuid();
            IsDebugEventLoggingEnabled = OrmLog.IsLogged(LogLevel.Debug); // Just to cache this value

            // Both Domain and Configuration are valid references here;
            // Configuration is already locked
            Configuration  = configuration;
            Name           = configuration.Name;
            identifier     = Interlocked.Increment(ref lastUsedIdentifier);
            CommandTimeout = configuration.DefaultCommandTimeout;
            allowSwitching = configuration.Supports(SessionOptions.AllowSwitching);

            // Handlers
            Handlers = domain.Handlers;
            Handler  = CreateSessionHandler();

            // Caches, registry
            EntityStateCache               = CreateSessionCache(configuration);
            EntityChangeRegistry           = new EntityChangeRegistry(this);
            EntitySetChangeRegistry        = new EntitySetChangeRegistry(this);
            ReferenceFieldsChangesRegistry = new ReferenceFieldsChangesRegistry(this);
            entitySetsWithInvalidState     = new HashSet <EntitySetBase>();

            // Events
            EntityEvents = new EntityEventBroker();
            Events       = new SessionEventAccessor(this, false);
            SystemEvents = new SessionEventAccessor(this, true);

            // Etc.
            PairSyncManager                 = new SyncManager(this);
            RemovalProcessor                = new RemovalProcessor(this);
            pinner                          = new Pinner(this);
            Operations                      = new OperationRegistry(this);
            NonPairedReferencesRegistry     = new NonPairedReferenceChangesRegistry(this);
            CommandProcessorContextProvider = new CommandProcessorContextProvider(this);

            // Validation context
            ValidationContext = Configuration.Supports(SessionOptions.ValidateEntities)
        ? (ValidationContext) new RealValidationContext()
        : new VoidValidationContext();

            // Creating Services
            Services = CreateServices();

            disposableSet = new DisposableSet();
            remapper      = new KeyRemapper(this);

            disableAutoSaveChanges = !configuration.Supports(SessionOptions.AutoSaveChanges);

            // Perform activation
            if (activate)
            {
                ActivateInternally();
            }

            // Query endpoint
            SystemQuery = Query = new QueryEndpoint(new QueryProvider(this));
        }
Esempio n. 3
0
        private async ValueTask DisposeImpl(bool isAsync)
        {
            if (isDisposed)
            {
                return;
            }

            sessionLifetimeToken.Expire();

            try {
                if (IsDebugEventLoggingEnabled)
                {
                    OrmLog.Debug(Strings.LogSessionXDisposing, this);
                }

                SystemEvents.NotifyDisposing();
                Events.NotifyDisposing();

                Services.DisposeSafely();
                if (isAsync)
                {
                    await Handler.DisposeSafelyAsync().ConfigureAwait(false);
                }
                else
                {
                    Handler.DisposeSafely();
                }
                CommandProcessorContextProvider.DisposeSafely();

                Domain.ReleaseSingleConnection();

                disposableSet.DisposeSafely();
                disposableSet = null;

                EntityChangeRegistry.Clear();
                EntitySetChangeRegistry.Clear();
                EntityStateCache.Clear();
                ReferenceFieldsChangesRegistry.Clear();
                NonPairedReferencesRegistry.Clear();
                Extensions.Clear();
            }
            finally {
                isDisposed = true;
            }
        }