Exemplo n.º 1
0
        /// <summary>
        /// This will dispose and reset all resources used to run the application
        /// </summary>
        /// <remarks>
        /// IMPORTANT: Never dispose this object if you require the Umbraco application to run, disposing this object
        /// is generally used for unit testing and when your application is shutting down after you have booted Umbraco.
        /// </remarks>
        void IDisposable.Dispose()
        {
            // Only operate if we haven't already disposed
            if (_disposed)
            {
                return;
            }

            using (new WriteLock(_disposalLocker))
            {
                // Check again now we're inside the lock
                if (_disposed)
                {
                    return;
                }

                //clear the cache
                if (ApplicationCache != null)
                {
                    ApplicationCache.ClearAllCache();
                }
                //reset all resolvers
                ResolverCollection.ResetAll();
                //reset resolution itself (though this should be taken care of by resetting any of the resolvers above)
                Resolution.Reset();

                //reset the instance objects
                this.ApplicationCache = null;
                if (_databaseContext != null) //need to check the internal field here
                {
                    if (DatabaseContext.IsDatabaseConfigured)
                    {
                        DatabaseContext.Database.Dispose();
                    }
                }
                this.DatabaseContext = null;
                this.Services        = null;
                this._isReady        = false; //set the internal field

                // Indicate that the instance has been disposed.
                _disposed = true;
            }
        }