Properly dispose DisplayPreferencesRepository

This commit is contained in:
Bond_009 2019-08-14 20:35:36 +02:00
parent e5b163b86a
commit 2fdf7f1098
3 changed files with 21 additions and 8 deletions

View File

@ -123,6 +123,8 @@ namespace Emby.Server.Implementations
{
private SqliteUserRepository _userRepository;
private SqliteDisplayPreferencesRepository _displayPreferencesRepository;
/// <summary>
/// Gets a value indicating whether this instance can self restart.
/// </summary>
@ -757,8 +759,12 @@ namespace Emby.Server.Implementations
UserDataManager = new UserDataManager(LoggerFactory, ServerConfigurationManager, () => UserManager);
serviceCollection.AddSingleton(UserDataManager);
var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LoggerFactory, JsonSerializer, ApplicationPaths, FileSystemManager);
serviceCollection.AddSingleton<IDisplayPreferencesRepository>(displayPreferencesRepo);
_displayPreferencesRepository = new SqliteDisplayPreferencesRepository(
LoggerFactory.CreateLogger<SqliteDisplayPreferencesRepository>(),
JsonSerializer,
ApplicationPaths,
FileSystemManager);
serviceCollection.AddSingleton<IDisplayPreferencesRepository>(_displayPreferencesRepository);
ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LoggerFactory, LocalizationManager);
serviceCollection.AddSingleton<IItemRepository>(ItemRepository);
@ -884,7 +890,7 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton(typeof(IResourceFileManager), typeof(ResourceFileManager));
displayPreferencesRepo.Initialize();
_displayPreferencesRepository.Initialize();
var userDataRepo = new SqliteUserDataRepository(LoggerFactory, ApplicationPaths);
@ -964,7 +970,10 @@ namespace Emby.Server.Implementations
/// <returns><see cref="Task{SqliteUserRepository}" />.</returns>
private SqliteUserRepository GetUserRepository()
{
var repo = new SqliteUserRepository(LoggerFactory, ApplicationPaths, JsonSerializer);
var repo = new SqliteUserRepository(
LoggerFactory.CreateLogger<SqliteUserRepository>(),
ApplicationPaths,
JsonSerializer);
repo.Initialize();
@ -1911,8 +1920,12 @@ namespace Emby.Server.Implementations
}
_userRepository?.Dispose();
_displayPreferencesRepository.Dispose();
}
_userRepository = null;
_displayPreferencesRepository = null;
_disposed = true;
}
}

View File

@ -21,8 +21,8 @@ namespace Emby.Server.Implementations.Data
{
private readonly IFileSystem _fileSystem;
public SqliteDisplayPreferencesRepository(ILoggerFactory loggerFactory, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, IFileSystem fileSystem)
: base(loggerFactory.CreateLogger(nameof(SqliteDisplayPreferencesRepository)))
public SqliteDisplayPreferencesRepository(ILogger<SqliteDisplayPreferencesRepository> logger, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, IFileSystem fileSystem)
: base(logger)
{
_jsonSerializer = jsonSerializer;
_fileSystem = fileSystem;

View File

@ -18,10 +18,10 @@ namespace Emby.Server.Implementations.Data
private readonly IJsonSerializer _jsonSerializer;
public SqliteUserRepository(
ILoggerFactory loggerFactory,
ILogger<SqliteUserRepository> logger,
IServerApplicationPaths appPaths,
IJsonSerializer jsonSerializer)
: base(loggerFactory.CreateLogger(nameof(SqliteUserRepository)))
: base(logger)
{
_jsonSerializer = jsonSerializer;