From c165f37bb96ad40d863a436795c21b9085f3fde9 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Fri, 22 Feb 2013 22:49:00 -0500 Subject: more dependancy injection. still just beginning --- MediaBrowser.Common/Kernel/BaseKernel.cs | 52 ++++++-------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) (limited to 'MediaBrowser.Common/Kernel/BaseKernel.cs') diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 202bd3cab..85954cb82 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -18,7 +18,6 @@ using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; -using SimpleInjector; namespace MediaBrowser.Common.Kernel { @@ -223,12 +222,6 @@ namespace MediaBrowser.Common.Kernel /// The task manager. public TaskManager TaskManager { get; private set; } - /// - /// Gets the iso manager. - /// - /// The iso manager. - public IIsoManager IsoManager { get; private set; } - /// /// Gets the rest services. /// @@ -347,20 +340,14 @@ namespace MediaBrowser.Common.Kernel /// Initializes a new instance of the class. /// /// The app host. - /// The iso manager. /// The logger. /// isoManager - protected BaseKernel(IApplicationHost appHost, IIsoManager isoManager, ILogger logger) + protected BaseKernel(IApplicationHost appHost, ILogger logger) { if (appHost == null) { throw new ArgumentNullException("appHost"); } - - if (isoManager == null) - { - throw new ArgumentNullException("isoManager"); - } if (logger == null) { @@ -368,7 +355,6 @@ namespace MediaBrowser.Common.Kernel } ApplicationHost = appHost; - IsoManager = isoManager; Logger = logger; } @@ -471,11 +457,6 @@ namespace MediaBrowser.Common.Kernel CompositionContainer.Catalog.Dispose(); } - /// - /// The ioc container - /// - private readonly Container _iocContainer = new Container(); - /// /// Composes the parts. /// @@ -486,19 +467,18 @@ namespace MediaBrowser.Common.Kernel CompositionContainer = GetSafeCompositionContainer(concreteTypes.Select(i => new TypeCatalog(i))); - ComposeExportedValues(CompositionContainer, _iocContainer); + RegisterExportedValues(CompositionContainer); CompositionContainer.ComposeParts(this); - ComposePartsWithIocContainer(concreteTypes, _iocContainer); + FindParts(concreteTypes); } /// /// Composes the parts with ioc container. /// /// All types. - /// The container. - protected virtual void ComposePartsWithIocContainer(Type[] allTypes, Container container) + protected virtual void FindParts(Type[] allTypes) { RestServices = GetExports(allTypes); WebSocketListeners = GetExports(allTypes); @@ -530,21 +510,20 @@ namespace MediaBrowser.Common.Kernel /// System.Object. private object Instantiate(Type type) { - return _iocContainer.GetInstance(type); + return ApplicationHost.CreateInstance(type); } /// /// Composes the exported values. /// /// The container. - /// - protected virtual void ComposeExportedValues(CompositionContainer container, Container iocContainer) + protected virtual void RegisterExportedValues(CompositionContainer container) { + ApplicationHost.Register(this); + container.ComposeExportedValue("logger", Logger); container.ComposeExportedValue("appHost", ApplicationHost); - - iocContainer.RegisterSingle(Logger); - iocContainer.RegisterSingle(ApplicationHost); + container.ComposeExportedValue("isoManager", ApplicationHost.Resolve()); } /// @@ -739,7 +718,6 @@ namespace MediaBrowser.Common.Kernel { DisposeTcpManager(); DisposeTaskManager(); - DisposeIsoManager(); DisposeHttpManager(); DisposeComposableParts(); @@ -753,18 +731,6 @@ namespace MediaBrowser.Common.Kernel } } - /// - /// Disposes the iso manager. - /// - private void DisposeIsoManager() - { - if (IsoManager != null) - { - IsoManager.Dispose(); - IsoManager = null; - } - } - /// /// Disposes the TCP manager. /// -- cgit v1.2.3