diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs
index 51d347caf..36ebcd802 100644
--- a/MediaBrowser.Controller/Kernel.cs
+++ b/MediaBrowser.Controller/Kernel.cs
@@ -88,12 +88,6 @@ namespace MediaBrowser.Controller
/// The user repository.
public IUserRepository UserRepository { get; set; }
- ///
- /// Gets the active user repository
- ///
- /// The display preferences repository.
- public IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
-
///
/// Gets the list of available item repositories
///
@@ -106,12 +100,6 @@ namespace MediaBrowser.Controller
/// The item repository.
public IItemRepository ItemRepository { get; set; }
- ///
- /// Gets the list of available DisplayPreferencesRepositories
- ///
- /// The display preferences repositories.
- public IEnumerable DisplayPreferencesRepositories { get; set; }
-
///
/// Gets the list of available item repositories
///
@@ -155,11 +143,7 @@ namespace MediaBrowser.Controller
UserDataRepository = GetRepository(UserDataRepositories, configurationManager.Configuration.UserDataRepository);
var userDataRepoTask = UserDataRepository.Initialize();
- // Get the current display preferences repository
- DisplayPreferencesRepository = GetRepository(DisplayPreferencesRepositories, configurationManager.Configuration.DisplayPreferencesRepository);
- var displayPreferencesRepoTask = DisplayPreferencesRepository.Initialize();
-
- return Task.WhenAll(itemRepoTask, userRepoTask, userDataRepoTask, displayPreferencesRepoTask);
+ return Task.WhenAll(itemRepoTask, userRepoTask, userDataRepoTask);
}
///
diff --git a/MediaBrowser.Server.Implementations/Library/DisplayPreferencesManager.cs b/MediaBrowser.Server.Implementations/Library/DisplayPreferencesManager.cs
index a8e51a75b..57a9c9d78 100644
--- a/MediaBrowser.Server.Implementations/Library/DisplayPreferencesManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/DisplayPreferencesManager.cs
@@ -1,5 +1,5 @@
-using MediaBrowser.Controller;
-using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
@@ -24,6 +24,12 @@ namespace MediaBrowser.Server.Implementations.Library
///
private readonly ConcurrentDictionary> _displayPreferences = new ConcurrentDictionary>();
+ ///
+ /// Gets the active user repository
+ ///
+ /// The display preferences repository.
+ public IDisplayPreferencesRepository Repository { get; set; }
+
///
/// Initializes a new instance of the class.
///
@@ -50,7 +56,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// DisplayPreferences.
private async Task RetrieveDisplayPreferences(Guid displayPreferencesId)
{
- var displayPreferences = await Kernel.Instance.DisplayPreferencesRepository.GetDisplayPreferences(displayPreferencesId).ConfigureAwait(false);
+ var displayPreferences = await Repository.GetDisplayPreferences(displayPreferencesId).ConfigureAwait(false);
return displayPreferences ?? new DisplayPreferences { Id = displayPreferencesId };
}
@@ -74,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.Library
try
{
- await Kernel.Instance.DisplayPreferencesRepository.SaveDisplayPreferences(displayPreferences,
+ await Repository.SaveDisplayPreferences(displayPreferences,
cancellationToken).ConfigureAwait(false);
var newValue = Task.FromResult(displayPreferences);
diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs
index c782eac18..7fef4935d 100644
--- a/MediaBrowser.ServerApplication/ApplicationHost.cs
+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs
@@ -220,6 +220,7 @@ namespace MediaBrowser.ServerApplication
RegisterSingleInstance(() => new LuceneSearchEngine());
+ await ConfigureRepositories().ConfigureAwait(false);
SetKernelProperties();
SetStaticProperties();
}
@@ -235,7 +236,6 @@ namespace MediaBrowser.ServerApplication
Parallel.Invoke(
() => ServerKernel.UserDataRepositories = GetExports(),
() => ServerKernel.UserRepositories = GetExports(),
- () => ServerKernel.DisplayPreferencesRepositories = GetExports(),
() => ServerKernel.ItemRepositories = GetExports(),
() => ServerKernel.WeatherProviders = GetExports(),
() => ServerKernel.ImageEnhancers = GetExports().OrderBy(e => e.Priority).ToArray(),
@@ -243,6 +243,21 @@ namespace MediaBrowser.ServerApplication
);
}
+ ///
+ /// Configures the repositories.
+ ///
+ /// Task.
+ private async Task ConfigureRepositories()
+ {
+ var displayPreferencesRepositories = GetExports();
+
+ var repo = GetRepository(displayPreferencesRepositories, ServerConfigurationManager.Configuration.DisplayPreferencesRepository);
+
+ await repo.Initialize().ConfigureAwait(false);
+
+ ((DisplayPreferencesManager)DisplayPreferencesManager).Repository = repo;
+ }
+
///
/// Dirty hacks
///
@@ -456,5 +471,21 @@ namespace MediaBrowser.ServerApplication
process.WaitForExit();
}
}
+
+ ///
+ /// Gets the repository.
+ ///
+ ///
+ /// The repositories.
+ /// The name.
+ /// ``0.
+ private T GetRepository(IEnumerable repositories, string name)
+ where T : class, IRepository
+ {
+ var enumerable = repositories as T[] ?? repositories.ToArray();
+
+ return enumerable.FirstOrDefault(r => string.Equals(r.Name, name, StringComparison.OrdinalIgnoreCase)) ??
+ enumerable.FirstOrDefault();
+ }
}
}