view MetroWpf/MetroWpf/App.xaml.cs @ 60:fc62c971a117

upload to blog
author Steven Hollidge <stevenhollidge@hotmail.com>
date Sat, 21 Apr 2012 21:19:39 +0100
parents a8b50a087544
children
line wrap: on
line source

using System.Diagnostics;
using System.Reflection;
using System.Windows;
using MetroWpf.Framework.Interfaces;
using MetroWpf.Xaml.Binding;
using Microsoft.Practices.ServiceLocation;
using Ninject;

namespace MetroWpf
{
    /// <summary>
    /// Application startup for initialisation and config
    /// </summary>
    public partial class App : Application
    {
        protected override void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            InitializeIoC();
            base.OnStartup(e);
            InitializeWpfApplication();
            InitializeBindingErrorTrace();
            LogApplicationStartup();
        }

        private static void InitializeBindingErrorTrace()
        {
            BindingErrorTraceListener.SetTrace();
        }

        private static void InitializeWpfApplication()
        {
            ServiceLocator.Current.GetInstance<IWpfApplication>().Initialize();
            //new Locator().WpfApplication.Initialize();
        }

        private static void LogApplicationStartup()
        {
            var fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
            //Log.Info("{0} {1} Startup",
            //          Assembly.GetExecutingAssembly().GetName(),
            //          fvi.ProductVersion);
        }

        private static void InitializeIoC()
        {
            var kernel = new StandardKernel(new IoCModule());
            var adapter = new NinjectServiceLocatorExt(kernel);
            ServiceLocator.SetLocatorProvider(() => adapter);
            kernel.Bind<IServiceLocator>().ToConstant(ServiceLocator.Current);

            //Resources["ServiceLocator"] = ServiceLocator.Current;
        }
    }
}