protected virtual void Reset() { // reset and dispose scopes // ensures we don't leak an opened database connection // which would lock eg SqlCe .sdf files if (Factory?.TryGetInstance <IScopeProvider>() is ScopeProvider scopeProvider) { Scope scope; while ((scope = scopeProvider.AmbientScope) != null) { scope.Reset(); scope.Dispose(); } } Current.Reset(); // disposes the factory // reset all other static things that should not be static ;( UriUtility.ResetAppDomainAppVirtualPath(); SettingsForTests.Reset(); // fixme - should it be optional? Mapper.Reset(); // clear static events DocumentRepository.ClearScopeEvents(); MediaRepository.ClearScopeEvents(); MemberRepository.ClearScopeEvents(); ContentTypeService.ClearScopeEvents(); MediaTypeService.ClearScopeEvents(); MemberTypeService.ClearScopeEvents(); }