Merge pull request #1624 from Bond-009/nullref

Fix possible Nullref
This commit is contained in:
dkanada 2019-08-14 12:42:58 -07:00 committed by GitHub
commit ca12763adc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 16 deletions

View File

@ -121,6 +121,10 @@ namespace Emby.Server.Implementations
/// </summary> /// </summary>
public abstract class ApplicationHost : IServerApplicationHost, IDisposable public abstract class ApplicationHost : IServerApplicationHost, IDisposable
{ {
private SqliteUserRepository _userRepository;
private SqliteDisplayPreferencesRepository _displayPreferencesRepository;
/// <summary> /// <summary>
/// Gets a value indicating whether this instance can self restart. /// Gets a value indicating whether this instance can self restart.
/// </summary> /// </summary>
@ -291,8 +295,6 @@ namespace Emby.Server.Implementations
/// <value>The user data repository.</value> /// <value>The user data repository.</value>
private IUserDataManager UserDataManager { get; set; } private IUserDataManager UserDataManager { get; set; }
private IUserRepository UserRepository { get; set; }
internal SqliteItemRepository ItemRepository { get; set; } internal SqliteItemRepository ItemRepository { get; set; }
private INotificationManager NotificationManager { get; set; } private INotificationManager NotificationManager { get; set; }
@ -757,8 +759,12 @@ namespace Emby.Server.Implementations
UserDataManager = new UserDataManager(LoggerFactory, ServerConfigurationManager, () => UserManager); UserDataManager = new UserDataManager(LoggerFactory, ServerConfigurationManager, () => UserManager);
serviceCollection.AddSingleton(UserDataManager); serviceCollection.AddSingleton(UserDataManager);
var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LoggerFactory, JsonSerializer, ApplicationPaths, FileSystemManager); _displayPreferencesRepository = new SqliteDisplayPreferencesRepository(
serviceCollection.AddSingleton<IDisplayPreferencesRepository>(displayPreferencesRepo); LoggerFactory.CreateLogger<SqliteDisplayPreferencesRepository>(),
JsonSerializer,
ApplicationPaths,
FileSystemManager);
serviceCollection.AddSingleton<IDisplayPreferencesRepository>(_displayPreferencesRepository);
ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LoggerFactory, LocalizationManager); ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LoggerFactory, LocalizationManager);
serviceCollection.AddSingleton<IItemRepository>(ItemRepository); serviceCollection.AddSingleton<IItemRepository>(ItemRepository);
@ -766,9 +772,9 @@ namespace Emby.Server.Implementations
AuthenticationRepository = GetAuthenticationRepository(); AuthenticationRepository = GetAuthenticationRepository();
serviceCollection.AddSingleton(AuthenticationRepository); serviceCollection.AddSingleton(AuthenticationRepository);
UserRepository = GetUserRepository(); _userRepository = GetUserRepository();
UserManager = new UserManager(LoggerFactory, ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, this, JsonSerializer, FileSystemManager); UserManager = new UserManager(LoggerFactory, ServerConfigurationManager, _userRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, this, JsonSerializer, FileSystemManager);
serviceCollection.AddSingleton(UserManager); serviceCollection.AddSingleton(UserManager);
LibraryManager = new LibraryManager(this, LoggerFactory, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager, () => UserViewManager); LibraryManager = new LibraryManager(this, LoggerFactory, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager, () => UserViewManager);
@ -884,7 +890,7 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton(typeof(IResourceFileManager), typeof(ResourceFileManager)); serviceCollection.AddSingleton(typeof(IResourceFileManager), typeof(ResourceFileManager));
displayPreferencesRepo.Initialize(); _displayPreferencesRepository.Initialize();
var userDataRepo = new SqliteUserDataRepository(LoggerFactory, ApplicationPaths); var userDataRepo = new SqliteUserDataRepository(LoggerFactory, ApplicationPaths);
@ -961,10 +967,13 @@ namespace Emby.Server.Implementations
/// <summary> /// <summary>
/// Gets the user repository. /// Gets the user repository.
/// </summary> /// </summary>
/// <returns>Task{IUserRepository}.</returns> /// <returns><see cref="Task{SqliteUserRepository}" />.</returns>
private IUserRepository GetUserRepository() private SqliteUserRepository GetUserRepository()
{ {
var repo = new SqliteUserRepository(LoggerFactory, ApplicationPaths, JsonSerializer); var repo = new SqliteUserRepository(
LoggerFactory.CreateLogger<SqliteUserRepository>(),
ApplicationPaths,
JsonSerializer);
repo.Initialize(); repo.Initialize();
@ -1910,10 +1919,12 @@ namespace Emby.Server.Implementations
} }
} }
UserRepository.Dispose(); _userRepository?.Dispose();
_displayPreferencesRepository.Dispose();
} }
UserRepository = null; _userRepository = null;
_displayPreferencesRepository = null;
_disposed = true; _disposed = true;
} }

View File

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

View File

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