public void Dispose() { if (_disposed || _disposing) { return; } if (!_disposing) { Stop(); _disposing = true; } Logger?.Debug("Disposing application {Application} {Instance}", ApplicationConstants.ApplicationName, _instanceId); Logger?.Verbose("Disposing web host {Application} {Instance}", ApplicationConstants.ApplicationName, _instanceId); WebHost?.SafeDispose(); Logger?.Verbose("Disposing Application root scope {Application} {Instance}", ApplicationConstants.ApplicationName, _instanceId); Scope rootScope = AppRootScope.Top(); AppRootScope?.SafeDispose(); rootScope?.SafeDispose(); Logger?.Verbose("Disposing configuration {Application} {Instance}", ApplicationConstants.ApplicationName, _instanceId); Configuration?.SafeDispose(); Logger?.Debug("Application disposal complete, disposing logging {Application} {Instance}", ApplicationConstants.ApplicationName, _instanceId); if (Logger is IDisposable disposable) { Logger?.Verbose("Disposing Logger {Application} {Instance}", ApplicationConstants.ApplicationName, _instanceId); disposable.SafeDispose(); } else { Logger?.Debug("Logger is not disposable {Application} {Instance}", ApplicationConstants.ApplicationName, _instanceId); } Configuration = null; Logger = null; WebHost = null; HostBuilder = null; AppRootScope = null; _disposed = true; _disposing = false; }