From 8ce3e74e8112a94773df22827849bf274fc88198 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sun, 24 Feb 2013 16:53:54 -0500 Subject: More DI --- MediaBrowser.Controller/Kernel.cs | 64 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 33 deletions(-) (limited to 'MediaBrowser.Controller/Kernel.cs') diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 5ee590bde..d879b888b 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Plugins; +using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.IO; @@ -16,6 +17,7 @@ using MediaBrowser.Controller.Updates; using MediaBrowser.Controller.Weather; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Serialization; using MediaBrowser.Model.System; using System; using System.Collections.Generic; @@ -28,7 +30,7 @@ namespace MediaBrowser.Controller /// /// Class Kernel /// - public class Kernel : BaseKernel + public class Kernel : BaseKernel { /// /// The MB admin URL @@ -291,17 +293,24 @@ namespace MediaBrowser.Controller get { return 7359; } } + private readonly ITaskManager _taskManager; + /// /// Creates a kernel based on a Data path, which is akin to our current programdata path /// /// The app host. + /// The app paths. + /// The XML serializer. + /// The task manager. /// The logger. /// isoManager - public Kernel(IApplicationHost appHost, ILogger logger) - : base(appHost, logger) + public Kernel(IApplicationHost appHost, IServerApplicationPaths appPaths, IXmlSerializer xmlSerializer, ITaskManager taskManager, ILogger logger) + : base(appHost, appPaths, xmlSerializer, logger) { Instance = this; + _taskManager = taskManager; + // For now there's no real way to inject this properly BaseItem.Logger = logger; Ratings.Logger = logger; @@ -310,21 +319,10 @@ namespace MediaBrowser.Controller BaseMetadataProvider.Logger = logger; } - /// - /// Composes the exported values. - /// - protected override void RegisterExportedValues() - { - ApplicationHost.RegisterSingleInstance(this); - - base.RegisterExportedValues(); - } - /// /// Composes the parts with ioc container. /// - /// All types. - protected override void FindParts(Type[] allTypes) + protected override void FindParts() { InstallationManager = (InstallationManager)ApplicationHost.CreateInstance(typeof(InstallationManager)); FFMpegManager = (FFMpegManager)ApplicationHost.CreateInstance(typeof(FFMpegManager)); @@ -335,21 +333,21 @@ namespace MediaBrowser.Controller UserDataManager = (UserDataManager)ApplicationHost.CreateInstance(typeof(UserDataManager)); PluginSecurityManager = (PluginSecurityManager)ApplicationHost.CreateInstance(typeof(PluginSecurityManager)); - base.FindParts(allTypes); - - EntityResolutionIgnoreRules = GetExports(allTypes); - UserDataRepositories = GetExports(allTypes); - UserRepositories = GetExports(allTypes); - DisplayPreferencesRepositories = GetExports(allTypes); - ItemRepositories = GetExports(allTypes); - WeatherProviders = GetExports(allTypes); - IntroProviders = GetExports(allTypes); - PluginConfigurationPages = GetExports(allTypes); - ImageEnhancers = GetExports(allTypes).OrderBy(e => e.Priority).ToArray(); - PluginFolderCreators = GetExports(allTypes); - StringFiles = GetExports(allTypes); - EntityResolvers = GetExports(allTypes).OrderBy(e => e.Priority).ToArray(); - MetadataProviders = GetExports(allTypes).OrderBy(e => e.Priority).ToArray(); + base.FindParts(); + + EntityResolutionIgnoreRules = ApplicationHost.GetExports(); + UserDataRepositories = ApplicationHost.GetExports(); + UserRepositories = ApplicationHost.GetExports(); + DisplayPreferencesRepositories = ApplicationHost.GetExports(); + ItemRepositories = ApplicationHost.GetExports(); + WeatherProviders = ApplicationHost.GetExports(); + IntroProviders = ApplicationHost.GetExports(); + PluginConfigurationPages = ApplicationHost.GetExports(); + ImageEnhancers = ApplicationHost.GetExports().OrderBy(e => e.Priority).ToArray(); + PluginFolderCreators = ApplicationHost.GetExports(); + StringFiles = ApplicationHost.GetExports(); + EntityResolvers = ApplicationHost.GetExports().OrderBy(e => e.Priority).ToArray(); + MetadataProviders = ApplicationHost.GetExports().OrderBy(e => e.Priority).ToArray(); } /// @@ -471,7 +469,7 @@ namespace MediaBrowser.Controller { DisposeFileSystemManager(); - FileSystemManager = new FileSystemManager(this, Logger, TaskManager); + FileSystemManager = new FileSystemManager(this, Logger, _taskManager); FileSystemManager.StartWatchers(); } @@ -570,11 +568,11 @@ namespace MediaBrowser.Controller ProviderManager.ValidateCurrentlyRunningProviders(); // Any number of configuration settings could change the way the library is refreshed, so do that now - TaskManager.CancelIfRunningAndQueue(); + _taskManager.CancelIfRunningAndQueue(); if (refreshPeopleAfterUpdate) { - TaskManager.CancelIfRunningAndQueue(); + _taskManager.CancelIfRunningAndQueue(); } }); } -- cgit v1.2.3