Register and construct IUserManager and IUserRepository correctly

This commit is contained in:
Mark Monteiro 2020-04-04 19:31:14 -04:00
parent 84b48eb69c
commit 4daa5436fc
2 changed files with 21 additions and 56 deletions

View File

@ -246,12 +246,6 @@ namespace Emby.Server.Implementations
/// <value>The server configuration manager.</value> /// <value>The server configuration manager.</value>
public IServerConfigurationManager ServerConfigurationManager => (IServerConfigurationManager)ConfigurationManager; public IServerConfigurationManager ServerConfigurationManager => (IServerConfigurationManager)ConfigurationManager;
/// <summary>
/// Gets or sets the user manager.
/// </summary>
/// <value>The user manager.</value>
public IUserManager UserManager { get; set; }
public LocalizationManager LocalizationManager { get; set; } public LocalizationManager LocalizationManager { get; set; }
/// <summary> /// <summary>
@ -650,7 +644,7 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton<IBlurayExaminer>(new BdInfoExaminer(FileSystemManager)); serviceCollection.AddSingleton<IBlurayExaminer>(new BdInfoExaminer(FileSystemManager));
UserDataManager = new UserDataManager(LoggerFactory, ServerConfigurationManager, () => UserManager); UserDataManager = new UserDataManager(LoggerFactory, ServerConfigurationManager, Resolve<IUserManager>);
serviceCollection.AddSingleton(UserDataManager); serviceCollection.AddSingleton(UserDataManager);
_displayPreferencesRepository = new SqliteDisplayPreferencesRepository( _displayPreferencesRepository = new SqliteDisplayPreferencesRepository(
@ -664,21 +658,11 @@ namespace Emby.Server.Implementations
AuthenticationRepository = GetAuthenticationRepository(); AuthenticationRepository = GetAuthenticationRepository();
serviceCollection.AddSingleton(AuthenticationRepository); serviceCollection.AddSingleton(AuthenticationRepository);
_userRepository = GetUserRepository(); serviceCollection.AddSingleton<IUserRepository, SqliteUserRepository>();
UserManager = new UserManager( // TODO: Refactor to eliminate the circular dependency here so that Lazy<T> isn't required
LoggerFactory.CreateLogger<UserManager>(), serviceCollection.AddTransient(provider => new Lazy<IDtoService>(provider.GetRequiredService<IDtoService>));
_userRepository, serviceCollection.AddSingleton<IUserManager, UserManager>();
XmlSerializer,
NetworkManager,
Resolve<IImageProcessor>,
Resolve<IDtoService>,
this,
JsonSerializer,
FileSystemManager,
cryptoProvider);
serviceCollection.AddSingleton(UserManager);
// TODO: Add StartupOptions.FFmpegPath to IConfiguration so this doesn't need to be constructed manually // TODO: Add StartupOptions.FFmpegPath to IConfiguration so this doesn't need to be constructed manually
serviceCollection.AddSingleton<IMediaEncoder>(new MediaBrowser.MediaEncoding.Encoder.MediaEncoder( serviceCollection.AddSingleton<IMediaEncoder>(new MediaBrowser.MediaEncoding.Encoder.MediaEncoder(
@ -771,6 +755,7 @@ namespace Emby.Server.Implementations
_sessionManager = Resolve<ISessionManager>(); _sessionManager = Resolve<ISessionManager>();
_httpServer = Resolve<IHttpServer>(); _httpServer = Resolve<IHttpServer>();
((SqliteUserRepository)Resolve<IUserRepository>()).Initialize();
((ActivityRepository)Resolve<IActivityRepository>()).Initialize(); ((ActivityRepository)Resolve<IActivityRepository>()).Initialize();
_displayPreferencesRepository.Initialize(); _displayPreferencesRepository.Initialize();
@ -778,11 +763,12 @@ namespace Emby.Server.Implementations
SetStaticProperties(); SetStaticProperties();
((UserManager)UserManager).Initialize(); var userManager = (UserManager)Resolve<IUserManager>();
userManager.Initialize();
((UserDataManager)UserDataManager).Repository = userDataRepo; ((UserDataManager)UserDataManager).Repository = userDataRepo;
((SqliteItemRepository)Resolve<IItemRepository>()).Initialize(userDataRepo, UserManager); ((SqliteItemRepository)Resolve<IItemRepository>()).Initialize(userDataRepo, userManager);
FindParts(); FindParts();
} }
@ -853,21 +839,6 @@ namespace Emby.Server.Implementations
} }
} }
/// <summary>
/// Gets the user repository.
/// </summary>
/// <returns><see cref="Task{SqliteUserRepository}" />.</returns>
private SqliteUserRepository GetUserRepository()
{
var repo = new SqliteUserRepository(
LoggerFactory.CreateLogger<SqliteUserRepository>(),
ApplicationPaths);
repo.Initialize();
return repo;
}
private IAuthenticationRepository GetAuthenticationRepository() private IAuthenticationRepository GetAuthenticationRepository()
{ {
var repo = new AuthenticationRepository(LoggerFactory, ServerConfigurationManager); var repo = new AuthenticationRepository(LoggerFactory, ServerConfigurationManager);
@ -889,7 +860,7 @@ namespace Emby.Server.Implementations
BaseItem.ProviderManager = Resolve<IProviderManager>(); BaseItem.ProviderManager = Resolve<IProviderManager>();
BaseItem.LocalizationManager = LocalizationManager; BaseItem.LocalizationManager = LocalizationManager;
BaseItem.ItemRepository = Resolve<IItemRepository>(); BaseItem.ItemRepository = Resolve<IItemRepository>();
User.UserManager = UserManager; User.UserManager = Resolve<IUserManager>();
BaseItem.FileSystem = FileSystemManager; BaseItem.FileSystem = FileSystemManager;
BaseItem.UserDataManager = UserDataManager; BaseItem.UserDataManager = UserDataManager;
BaseItem.ChannelManager = Resolve<IChannelManager>(); BaseItem.ChannelManager = Resolve<IChannelManager>();
@ -984,7 +955,7 @@ namespace Emby.Server.Implementations
Resolve<IMediaSourceManager>().AddParts(GetExports<IMediaSourceProvider>()); Resolve<IMediaSourceManager>().AddParts(GetExports<IMediaSourceProvider>());
Resolve<INotificationManager>().AddParts(GetExports<INotificationService>(), GetExports<INotificationTypeFactory>()); Resolve<INotificationManager>().AddParts(GetExports<INotificationService>(), GetExports<INotificationTypeFactory>());
UserManager.AddParts(GetExports<IAuthenticationProvider>(), GetExports<IPasswordResetProvider>()); Resolve<IUserManager>().AddParts(GetExports<IAuthenticationProvider>(), GetExports<IPasswordResetProvider>());
IsoManager.AddParts(GetExports<IIsoMounter>()); IsoManager.AddParts(GetExports<IIsoMounter>());
} }

View File

@ -44,22 +44,14 @@ namespace Emby.Server.Implementations.Library
{ {
private readonly object _policySyncLock = new object(); private readonly object _policySyncLock = new object();
private readonly object _configSyncLock = new object(); private readonly object _configSyncLock = new object();
/// <summary>
/// The logger.
/// </summary>
private readonly ILogger _logger;
/// <summary> private readonly ILogger _logger;
/// Gets the active user repository.
/// </summary>
/// <value>The user repository.</value>
private readonly IUserRepository _userRepository; private readonly IUserRepository _userRepository;
private readonly IXmlSerializer _xmlSerializer; private readonly IXmlSerializer _xmlSerializer;
private readonly IJsonSerializer _jsonSerializer; private readonly IJsonSerializer _jsonSerializer;
private readonly INetworkManager _networkManager; private readonly INetworkManager _networkManager;
private readonly IImageProcessor _imageProcessor;
private readonly Func<IImageProcessor> _imageProcessorFactory; private readonly Lazy<IDtoService> _dtoServiceFactory;
private readonly Func<IDtoService> _dtoServiceFactory;
private readonly IServerApplicationHost _appHost; private readonly IServerApplicationHost _appHost;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly ICryptoProvider _cryptoProvider; private readonly ICryptoProvider _cryptoProvider;
@ -74,13 +66,15 @@ namespace Emby.Server.Implementations.Library
private IPasswordResetProvider[] _passwordResetProviders; private IPasswordResetProvider[] _passwordResetProviders;
private DefaultPasswordResetProvider _defaultPasswordResetProvider; private DefaultPasswordResetProvider _defaultPasswordResetProvider;
private IDtoService DtoService => _dtoServiceFactory.Value;
public UserManager( public UserManager(
ILogger<UserManager> logger, ILogger<UserManager> logger,
IUserRepository userRepository, IUserRepository userRepository,
IXmlSerializer xmlSerializer, IXmlSerializer xmlSerializer,
INetworkManager networkManager, INetworkManager networkManager,
Func<IImageProcessor> imageProcessorFactory, IImageProcessor imageProcessor,
Func<IDtoService> dtoServiceFactory, Lazy<IDtoService> dtoServiceFactory,
IServerApplicationHost appHost, IServerApplicationHost appHost,
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IFileSystem fileSystem, IFileSystem fileSystem,
@ -90,7 +84,7 @@ namespace Emby.Server.Implementations.Library
_userRepository = userRepository; _userRepository = userRepository;
_xmlSerializer = xmlSerializer; _xmlSerializer = xmlSerializer;
_networkManager = networkManager; _networkManager = networkManager;
_imageProcessorFactory = imageProcessorFactory; _imageProcessor = imageProcessor;
_dtoServiceFactory = dtoServiceFactory; _dtoServiceFactory = dtoServiceFactory;
_appHost = appHost; _appHost = appHost;
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
@ -600,7 +594,7 @@ namespace Emby.Server.Implementations.Library
try try
{ {
_dtoServiceFactory().AttachPrimaryImageAspectRatio(dto, user); DtoService.AttachPrimaryImageAspectRatio(dto, user);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -625,7 +619,7 @@ namespace Emby.Server.Implementations.Library
{ {
try try
{ {
return _imageProcessorFactory().GetImageCacheTag(item, image); return _imageProcessor.GetImageCacheTag(item, image);
} }
catch (Exception ex) catch (Exception ex)
{ {