Exemple #1
0
        public App()
        {
            DependencyEmbedder dependencyEmbedder = new DependencyEmbedder();

            dependencyEmbedder.AddPackage("Newtonsoft.Json");
            dependencyEmbedder.AddPackage("SharpDX.DirectInput");
            dependencyEmbedder.AddPackage("SharpDX");
            dependencyEmbedder.AddPackage("Hardcodet.Wpf.TaskbarNotification");
            dependencyEmbedder.AddPackage("Nefarius.ViGEm.Client");
            dependencyEmbedder.Initialize();
            string exePath = Assembly.GetExecutingAssembly().Location;
            string cwd     = Path.GetDirectoryName(exePath);

            Directory.SetCurrentDirectory(cwd);

            ApplicationContext globalContext = ApplicationContext.Global;

            globalContext.Resolvers.Add(Resolver.CreateSingleton(Dispatcher));
            globalContext.AddFromConfiguration(typeof(ApplicationConfiguration));
            globalContext.AddFromConfiguration(typeof(UI.UIConfiguration));

            singleInstanceProvider = new SingleInstanceProvider();
            argumentParser         = globalContext.Resolve <ArgumentParser>();
#if !DEBUG
            Dispatcher.UnhandledException += async(object sender, DispatcherUnhandledExceptionEventArgs e) => await UnhandledException(e.Exception);
#endif
        }
        public void SingletonTest()
        {
            ApplicationContext context = new ApplicationContext();

            context.Resolvers.Add(Resolver.CreateSingleton(new object()));
            object first  = context.Resolve <object>();
            object second = context.Resolve <object>();

            Assert.AreSame(first, second);
        }
        public void SimpleTest()
        {
            int expectedValue          = 5;
            ApplicationContext context = new ApplicationContext();

            context.Resolvers.Add(Resolver.CreateSingleton(expectedValue));
            int actualValue = context.Resolve <int>();

            Assert.AreEqual(expectedValue, actualValue);
        }
        public void CloseDependencyTest()
        {
            var mock = new Mock <IDisposable>();

            mock.Setup(p => p.Dispose());
            ApplicationContext context = new ApplicationContext();

            context.Resolvers.Add(Resolver.CreateSingleton(mock.Object));
            IDisposable value = context.Resolve <IDisposable>();

            Assert.AreEqual(mock.Object, value);
            mock.Verify(p => p.Dispose(), Times.Never);
            context.Close();
            mock.Verify(p => p.Dispose(), Times.Once);
        }
Exemple #5
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            ApplicationContext globalContext = ApplicationContext.Global;

            globalContext.Resolvers.Add(Resolver.CreateSingleton(Dispatcher));
            globalContext.AddFromConfiguration(typeof(CoreConfiguration));
            globalContext.AddFromConfiguration(typeof(ApiConfiguration));
            globalContext.AddFromConfiguration(typeof(ApplicationConfiguration));
            globalContext.AddFromConfiguration(typeof(UI.UIConfiguration));

            var singleInstanceProvider = globalContext.Resolve <SingleInstanceProvider>();
            var argumentParser         = globalContext.Resolve <ArgumentParser>();

            globalContext.Discover();
            if (singleInstanceProvider.TryGetLock())
            {
                singleInstanceProvider.StartNamedPipe();
                try
                {
                    var mainWindow = ApplicationContext.Global.Resolve <MainWindow>();
                    mainWindowViewModel = mainWindow.ViewModel;
                    MainWindow          = mainWindow;
                    singleInstanceProvider.ShowEvent += mainWindow.ForceShow;
                    if (!argumentParser.Minimized)
                    {
                        mainWindow.Show();
                    }
#if !DEBUG
                    ApplicationContext.Global.Resolve <Devices.Input.Mouse.MouseHook>().StartHook();
#endif
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                    Application.Current.Shutdown();
                }
            }
            else
            {
                singleInstanceProvider.Notify();
                Application.Current.Shutdown();
            }
        }