From 8ce3e74e8112a94773df22827849bf274fc88198 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sun, 24 Feb 2013 16:53:54 -0500 Subject: More DI --- MediaBrowser.ServerApplication/App.xaml.cs | 194 ++--------------------------- 1 file changed, 11 insertions(+), 183 deletions(-) (limited to 'MediaBrowser.ServerApplication/App.xaml.cs') diff --git a/MediaBrowser.ServerApplication/App.xaml.cs b/MediaBrowser.ServerApplication/App.xaml.cs index 1b6b6f98e3..5808120adf 100644 --- a/MediaBrowser.ServerApplication/App.xaml.cs +++ b/MediaBrowser.ServerApplication/App.xaml.cs @@ -1,26 +1,13 @@ -using BDInfo; -using MediaBrowser.ClickOnce; -using MediaBrowser.Common.IO; +using MediaBrowser.ClickOnce; +using MediaBrowser.Common.Implementations.Serialization; using MediaBrowser.Common.Kernel; -using MediaBrowser.Common.Net; using MediaBrowser.Controller; -using MediaBrowser.IsoMounter; using MediaBrowser.Logging.Nlog; -using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; -using MediaBrowser.Model.MediaInfo; -using MediaBrowser.Model.Updates; -using MediaBrowser.Networking.Management; -using MediaBrowser.Networking.Udp; -using MediaBrowser.Networking.Web; -using MediaBrowser.Networking.WebSocket; using MediaBrowser.Server.Uninstall; -using MediaBrowser.ServerApplication.Implementations; using Microsoft.Win32; -using SimpleInjector; using System; using System.Diagnostics; -using System.IO; using System.Linq; using System.Net.Cache; using System.Threading; @@ -35,7 +22,7 @@ namespace MediaBrowser.ServerApplication /// /// Interaction logic for App.xaml /// - public partial class App : Application, IApplicationHost + public partial class App : Application { /// /// Defines the entry point of the application. @@ -78,16 +65,11 @@ namespace MediaBrowser.ServerApplication protected ILogger Logger { get; set; } /// - /// Gets or sets the log file path. + /// Gets or sets the composition root. /// - /// The log file path. - public string LogFilePath { get; private set; } - - /// - /// The container - /// - private Container _container = new Container(); - + /// The composition root. + protected ApplicationHost CompositionRoot { get; set; } + /// /// Initializes a new instance of the class. /// @@ -135,12 +117,6 @@ namespace MediaBrowser.ServerApplication get { return "MediaBrowser.Server.Uninstall.exe"; } } - /// - /// Gets or sets the iso manager. - /// - /// The iso manager. - private IIsoManager IsoManager { get; set; } - /// /// Gets or sets a value indicating whether [last run at startup value]. /// @@ -198,13 +174,13 @@ namespace MediaBrowser.ServerApplication /// protected async void LoadKernel() { - Kernel = new Kernel(this, Logger); + CompositionRoot = new ApplicationHost(Logger); - RegisterResources(); + Kernel = CompositionRoot.Kernel; try { - new MainWindow(Logger).Show(); + new MainWindow(new JsonSerializer(), Logger).Show(); var now = DateTime.UtcNow; @@ -281,6 +257,7 @@ namespace MediaBrowser.ServerApplication base.OnExit(e); Kernel.Dispose(); + CompositionRoot.Dispose(); } /// @@ -391,17 +368,6 @@ namespace MediaBrowser.ServerApplication Dispatcher.Invoke(Shutdown); } - /// - /// Reloads the logger. - /// - /// - public void ReloadLogger() - { - LogFilePath = Path.Combine(Kernel.ApplicationPaths.LogDirectoryPath, "Server-" + DateTime.Now.Ticks + ".log"); - - NlogManager.AddFileTarget(LogFilePath, Kernel.Configuration.EnableDebugLevelLogging); - } - /// /// Gets the image. /// @@ -477,143 +443,5 @@ namespace MediaBrowser.ServerApplication RenderOptions.SetBitmapScalingMode(bitmap, BitmapScalingMode.Fant); return bitmap; } - - /// - /// Gets or sets a value indicating whether this instance can self update. - /// - /// true if this instance can self update; otherwise, false. - public bool CanSelfUpdate - { - get { return ClickOnceHelper.IsNetworkDeployed; } - } - - /// - /// Checks for update. - /// - /// The cancellation token. - /// The progress. - /// Task{CheckForUpdateResult}. - public Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) - { - return new ApplicationUpdateCheck().CheckForApplicationUpdate(cancellationToken, progress); - } - - /// - /// Updates the application. - /// - /// The cancellation token. - /// The progress. - /// Task. - public Task UpdateApplication(CancellationToken cancellationToken, IProgress progress) - { - return new ApplicationUpdater().UpdateApplication(cancellationToken, progress); - } - - /// - /// Registers resources that classes will depend on - /// - private void RegisterResources() - { - RegisterSingleInstance(this); - RegisterSingleInstance(Logger); - - IsoManager = new PismoIsoManager(Logger); - - RegisterSingleInstance(IsoManager); - RegisterSingleInstance(() => new BdInfoExaminer()); - RegisterSingleInstance(() => new NetworkManager()); - RegisterSingleInstance(() => new DotNetZipClient()); - RegisterSingleInstance(() => new AlchemyServer(Logger)); - Register(typeof(IUdpServer), typeof(UdpServer)); - RegisterSingleInstance(() => new HttpServer(this, Kernel, Logger, "Media Browser", "index.html")); - } - - /// - /// Creates an instance of type and resolves all constructor dependancies - /// - /// The type. - /// System.Object. - public object CreateInstance(Type type) - { - try - { - return _container.GetInstance(type); - } - catch - { - Logger.Error("Error creating {0}", type.Name); - - throw; - } - } - - /// - /// Registers the specified obj. - /// - /// - /// The obj. - public void RegisterSingleInstance(T obj) - where T : class - { - _container.RegisterSingle(obj); - } - - /// - /// Registers the specified func. - /// - /// - /// The func. - public void Register(Func func) - where T : class - { - _container.Register(func); - } - - /// - /// Registers the single instance. - /// - /// - /// The func. - public void RegisterSingleInstance(Func func) - where T : class - { - _container.RegisterSingle(func); - } - - /// - /// Resolves this instance. - /// - /// - /// ``0. - public T Resolve() - { - return (T)_container.GetRegistration(typeof(T), true).GetInstance(); - } - - /// - /// Resolves this instance. - /// - /// - /// ``0. - public T TryResolve() - { - var result = _container.GetRegistration(typeof(T), false); - - if (result == null) - { - return default(T); - } - return (T)result.GetInstance(); - } - - /// - /// Registers the specified service type. - /// - /// Type of the service. - /// Type of the concrete. - public void Register(Type serviceType, Type implementation) - { - _container.Register(serviceType, implementation); - } } } -- cgit v1.2.3