protected override void ConfigureServiceLocator()
        {
            base.ConfigureServiceLocator();

            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(FindViewModelTypeFromViewType);
            ViewModelLocationProvider.SetDefaultViewModelFactory(ResolveViewModelFromType);
        }
Esempio n. 2
0
 /// <summary>
 /// Configures the <see cref="Prism.Mvvm.ViewModelLocator"/> used by Prism.
 /// </summary>
 protected virtual void ConfigureViewModelLocator()
 {
     ViewModelLocationProvider.SetDefaultViewModelFactory((view, type) =>
     {
         return(Container.Resolve(type));
     });
 }
Esempio n. 3
0
 internal static void ConfigureViewModelLocator(IContainerProvider containerProvider)
 {
     ViewModelLocationProvider.SetDefaultViewModelFactory((view, type) =>
     {
         return(containerProvider.Resolve(type));
     });
 }
Esempio n. 4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            logger.Debug($"VK Postpone Helper ({Version}) пытается запуститься");

            if (SingleInstance.IsOnlyInstance() == false)
            {
                //SingleInstance.ShowFirstInstance();
                logger.Debug("Уже обнаружена запущенная версия программы. Завершение текущего экземпляра.");
                Current.Shutdown();
                return;
            }

            base.OnStartup(e);

            Current.DispatcherUnhandledException += CurrentOnDispatcherUnhandledException;
            Current.ShutdownMode = ShutdownMode.OnMainWindowClose;

            var bs = new Bootstrapper();

            ViewModelLocationProvider.SetDefaultViewModelFactory(type => bs.Container.Resolve(type));

            bs.Run();
            Container = bs.Container;

            logger.Debug($"VK Postpone Helper версии {Version} запущен.");
        }
Esempio n. 5
0
 public virtual void ConfigureViewModelLocator()
 {
     ViewModelLocationProvider.SetDefaultViewModelFactory((view, type) =>
     {
         return(_containerExtension.ResolveViewModelForView(view, type));
     });
 }
Esempio n. 6
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.RegisterErrorHandler();

            Jupiter.Properties.Settings.Default.Upgrade();

            ViewModelLocationProvider.SetDefaultViewModelFactory(x => this.Container.Resolve(x));

            var lifetimeManager  = new ContainerControlledLifetimeManager();
            var lifetimeManager2 = new ContainerControlledLifetimeManager();
            var lifetimeManager3 = new ContainerControlledLifetimeManager();
            var lifetimeManager4 = new ContainerControlledLifetimeManager();

            var ea = new Prism.Events.EventAggregator();

            this.Container.RegisterInstance <Prism.Events.IEventAggregator>(ea);
            this.Container.RegisterType <Interfaces.INodeTreeModel, Models.NodeTreeModel>(lifetimeManager);
            this.Container.RegisterType <Interfaces.INodeInfoDataGrid, Models.NodeInfoDataGridModel>(lifetimeManager2);
            this.Container.RegisterType <Interfaces.ISubscriptionModel, Models.SubscriptionModel>(lifetimeManager3);
            this.Container.RegisterType <Interfaces.IOneTimeAccessModel, Models.OneTimeAccessModel>(lifetimeManager4);

            var c = new Client(ea);

            this.Container.RegisterInstance <Interfaces.IConnection>(c);
            this.Container.RegisterInstance <Interfaces.IReferenceFetchable>(c);
            this.Container.RegisterInstance <Interfaces.INodeInfoGetter>(c);
            this.Container.RegisterInstance <Interfaces.ISubscriptionOperatable>(c);
            this.Container.RegisterInstance <Interfaces.IOneTimeAccessOperator>(c);

            var references = new OPCUAReference(c, null, ea);

            this.Container.RegisterInstance <Interfaces.IReference>(references);

            this.Container.Resolve <Views.MainWindow>().Show();
        }
Esempio n. 7
0
        private void Initialize()
        {
            // register types, platform specific
            Resolver.Container.RegisterInstance <ILogCache>(new LogCache());
            Resolver.Container.RegisterType <IToastHelper, ToastHelper>();
            Resolver.Container.RegisterType <ILiveTileUpdater, LiveTileUpdater>();
            Resolver.Container.RegisterType <IResourceRepository, ResourceRepository>(new ContainerControlledLifetimeManager());
            Resolver.Container.RegisterType <IMobileServicesAuthentication, MobileServicesAuthentication>();

            // register container extensions
            Resolver.Container.AddNewExtension <CoreUnityContainerExtension>();
            Resolver.Container.AddNewExtension <CommonUnityContainerExtension>();

            // register view mappings
            Resolver.Resolve <INavigationService>().RegisterView <DailyProgressPageViewModel, DailyProgressPage>();
            Resolver.Resolve <INavigationService>().RegisterView <SettingsPageViewModel, SettingsPage>();
            Resolver.Resolve <INavigationService>().RegisterView <HistoryPageViewModel, HistoryPage>();
            Resolver.Resolve <INavigationService>().RegisterView <InfoPageViewModel, InfoPage>();
            Resolver.Resolve <INavigationService>().RegisterView <SetupUnitSystemPageViewModel, SetupUnitSystemPage>();

            ViewModelLocationProvider.SetDefaultViewModelFactory(
                delegate(Type viewtype)
            {
                var result = Resolver.Container.Resolve(viewtype);
                return(result);
            });
        }
Esempio n. 8
0
        protected override void OnStartup(StartupEventArgs e)
        {
            BasicConfigurator.Configure();

            base.OnStartup(e);
            var unityContainer = new UnityContainer();

            unityContainer.RegisterInstance(eventAggregator);
            unityContainer.RegisterType <ICultureInfoProvider, ICultureInfoProvider>();
            unityContainer.RegisterType <ICultureInfoProvider, CultureInfoProvider>();
            unityContainer.RegisterType <ILanguageDetector, GoogleLanguageDetector>();
            unityContainer.RegisterType <ILocationsDataProvider, GoogleLocationsDataProvider>();
            unityContainer.RegisterType <ISettingsProvider, MapsRouteLocator.Business.SettingsProvider>();
            unityContainer.RegisterType <ILocationsQueryProvider, GoogleLocationsQueryProvider>();
            unityContainer.RegisterType <IRoutesQueryProvider, GoogleRoutesQueryProvider>();
            unityContainer.RegisterType <ISearchHistoryReader, SearchHistoryReader>();
            unityContainer.RegisterType <ISearchHistoryWriter, SearchHistoryWriter>();
            unityContainer.RegisterType <ILocationsRepository, LocationsRepository>();
            unityContainer.RegisterType <IRoutesExistanceQueryProvider, GoogleRoutesExistanceQueryProvider>();
            unityContainer.RegisterType <IRoutesExistenceValidator, GoogleRoutesExistenceValidator>();
            ViewModelLocationProvider.SetDefaultViewModelFactory(type => unityContainer.Resolve(type));
            var window = unityContainer.Resolve <MainWindow>();

            window.ShowDialog();
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes the Frame and its content.
        /// </summary>
        /// <param name="args">The <see cref="IActivatedEventArgs"/> instance containing the event data.</param>
        /// <returns>A task of a Frame that holds the app content.</returns>
        protected async Task <Frame> InitializeFrameAsync(IActivatedEventArgs args)
        {
            // Create a Frame to act as the navigation context and navigate to the first page
            var rootFrame = new Frame();

            if (ExtendedSplashScreenFactory != null)
            {
                Page extendedSplashScreen = this.ExtendedSplashScreenFactory.Invoke(args.SplashScreen);
                rootFrame.Content = extendedSplashScreen;
            }

            rootFrame.Navigated += OnNavigated;

            var frameFacade = new FrameFacadeAdapter(rootFrame);

            //Initialize PrismApplication common services
            SessionStateService = new SessionStateService();

            //Configure VisualStateAwarePage with the ability to get the session state for its frame
            VisualStateAwarePage.GetSessionStateForFrame =
                frame => SessionStateService.GetSessionStateForFrame(frameFacade);

            //Associate the frame with a key
            SessionStateService.RegisterFrame(frameFacade, "AppFrame");

            NavigationService = CreateNavigationService(frameFacade, SessionStateService);

            DeviceGestureService = CreateDeviceGestureService();
            DeviceGestureService.GoBackRequested    += OnGoBackRequested;
            DeviceGestureService.GoForwardRequested += OnGoForwardRequested;

            // Set a factory for the ViewModelLocator to use the default resolution mechanism to construct view models
            ViewModelLocationProvider.SetDefaultViewModelFactory(Resolve);

            OnRegisterKnownTypesForSerialization();
            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                await SessionStateService.RestoreSessionStateAsync();
            }

            await OnInitializeAsync(args);

            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                // Restore the saved session state and navigate to the last page visited
                try
                {
                    SessionStateService.RestoreFrameState();
                    NavigationService.RestoreSavedNavigation();
                    _isRestoringFromTermination = true;
                }
                catch (SessionStateServiceException)
                {
                    // Something went wrong restoring state.
                    // Assume there is no state and continue
                }
            }

            return(rootFrame);
        }
Esempio n. 10
0
        protected override void OnStartup(StartupEventArgs e)
        {
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("pt-PT");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-PT");
            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
                                                                   XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;

            //resolve all the viewmodels
            container.RegisterMany(new[] {
                typeof(HomeViewModel),
                typeof(SaftCustomersViewModel),
                typeof(SaftErrorsViewModel),
                typeof(SaftHeaderViewModel),
                typeof(SaftInvoicesSummaryViewModel),
                typeof(SaftInvoicesViewModel),
                typeof(SaftProductsViewModel),
                typeof(SaftSuppliersViewModel),
                typeof(SaftTaxesViewModel),
                typeof(SaftValidationResumeViewModel),
            });

            //resolve the viewmodels
            ViewModelLocationProvider.SetDefaultViewModelFactory((type) => container.Resolve(type));

            Current.MainWindow = new MainWindow();
            //show the main window
            Current.MainWindow.Show();

            base.OnStartup(e);
        }
        public async Task AutoWireViewModel_With_Custom_Resolver_And_Factory()
        {
            await DispatcherHelper.ExecuteOnUIThread(() =>
            {
                var page = new MockPage();

                // Set the ViewTypeToViewModelTypeResolver
                ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
                {
                    var viewName = viewType.FullName;

                    // The ViewModel is in the same namespace as the View
                    var viewModelName = String.Format("{0}ViewModel", viewName);
                    return(Type.GetType(viewModelName));
                });

                // Set the ViewTypeToViewModelTypeResolver
                ViewModelLocationProvider.SetDefaultViewModelFactory((viewModelType) =>
                {
                    // The ViewModel has a constructor with no parameters
                    return(Activator.CreateInstance(viewModelType) as ViewModelBase);
                });

                // Fire AutoWireViewModelChanged
                ViewModelLocator.SetAutoWireViewModel(page, true);

                Assert.IsNotNull(page.DataContext);
                Assert.IsInstanceOfType(page.DataContext, typeof(MockPageViewModel));
            });
        }
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
            ViewModelLocationProvider.SetDefaultViewModelFactory((type) => Container.Resolve(type));

            Container.RegisterType <IRegionNavigationContentLoader, ScopedRegionNavigationContentLoader>(new ContainerControlledLifetimeManager());
        }
Esempio n. 13
0
        protected override void ConfigureViewModelLocator()
        {
            base.ConfigureViewModelLocator();

            // override Prism viewmodel resolution
            ViewModelLocationProvider.SetDefaultViewModelFactory(ViewModelFactory);
        }
Esempio n. 14
0
        public App()
        {
            DispatcherHelper.Initialize();
            var builder = new ContainerBuilder();

            builder.Register(m => Messenger.Default).As <IMessenger>();
            builder.Register(s => SynchronizationContext.Current).As <SynchronizationContext>();
            // register all windows
            Assembly.GetExecutingAssembly().GetTypes().Where(t => !t.IsAbstract && t.IsPublic && typeof(Window).IsAssignableFrom(t)).ToList().ForEach(
                windowType =>
            {
                builder.RegisterType(windowType).InstancePerDependency();
            });
            // register all view models
            Assembly.GetExecutingAssembly().GetTypes().Where(t => !t.IsAbstract && t.IsPublic && typeof(BaseViewModel).IsAssignableFrom(t)).ToList().ForEach(
                viewModelType =>
            {
                builder.RegisterType(viewModelType).UsingConstructor(typeof(IMessenger), typeof(SynchronizationContext)).InstancePerDependency().OnActivated(vm => ((BaseViewModel)vm.Instance).OnInstanceActivated())
                .OnActivating(vm => ((BaseViewModel)vm.Instance).OnInstanceActivating());
            });
            // build container and assign instance
            Variables.AutoFacContainer = builder.Build();
            // override default view model factory with AutoFac
            ViewModelLocationProvider.SetDefaultViewModelFactory(type => Variables.AutoFacContainer.Resolve(type));
        }
Esempio n. 15
0
        protected override void ConfigureViewModelLocator()
        {
            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(
                NavigationServiceExtensions.GetViewModelType);

            ViewModelLocationProvider.SetDefaultViewModelFactory(Resolve);
        }
        protected override Task OnInitializeAsync(IActivatedEventArgs args)
        {
            Disptacher = Window.Current.Dispatcher;

            //services
            Container.RegisterType <ILocalService, LocalService>(new ContainerControlledLifetimeManager());

            //repositories
            Container.RegisterType <IUserRepository, UserRepository>(new ContainerControlledLifetimeManager());

            //repositories
            Container.RegisterType <IGetUserListInteractor, GetUserListInteractor>(new ContainerControlledLifetimeManager());

            //mapper
            Container.RegisterType <IEntityMapper <UserEntity, User>, UserEntityMapper>(new ContainerControlledLifetimeManager());

            // register view models
            ViewModelLocationProvider.SetDefaultViewModelFactory((type) =>
            {
                return(Container.Resolve(type));
            });

            //view models
            //Container.RegisterType<UserListPageViewModel, UserListPageViewModel>(new ContainerControlledLifetimeManager());

            return(Task.FromResult <object>(null));
        }
Esempio n. 17
0
        protected override void OnStartup(StartupEventArgs e)
        {
            this.ConfigureUnityContainer();
            ViewModelLocationProvider.SetDefaultViewModelFactory((type) => Container.Resolve(type));

            base.OnStartup(e);
        }
Esempio n. 18
0
        protected override Task OnInitializeAsync(IActivatedEventArgs args)
        {
            var viewRegistrations = this.Container.Resolve <IEnumerable <ViewRegistration> >().ToList();

            foreach (var r in viewRegistrations)
            {
                this.ViewRegistrations.Add(r.Token, r.ViewType);
            }

            var controlRegistrations = this.ResolveControlRegistrations();

            var viewModelRegistry = viewRegistrations.Select(r => new { Type = r.ViewType, r.ViewModelType })
                                    .Concat(controlRegistrations.Select(r => new { Type = r.ControlType, r.ViewModelType }))
                                    .ToDictionary(a => a.Type, a => a.ViewModelType);

            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(viewType => viewModelRegistry[viewType]);

            ViewModelLocationProvider.SetDefaultViewModelFactory(this.CreateViewModel);

            // Documentation on working with tiles can be found at http://go.microsoft.com/fwlink/?LinkID=288821&clcid=0x409
            //var _tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
            //_tileUpdater.StartPeriodicUpdate(new Uri(Constants.ServerAddress + "/api/TileNotification"), PeriodicUpdateRecurrence.HalfHour);

            return(base.OnInitializeAsync(args));
        }
Esempio n. 19
0
 internal static void ConfigureViewModelLocator()
 {
     ViewModelLocationProvider.SetDefaultViewModelFactory((view, type, singleton) =>
     {
         return(ContainerLocator.Container.Resolve(type, singleton));
     });
 }
Esempio n. 20
0
        protected override void OnStartup(StartupEventArgs e)
        {
            //Uncomment this code to test against other cultures.
            //System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ja-JP");
            //System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ja-JP");

            base.OnStartup(e);

            ThemeManager.ApplicationTheme = new Office2013Theme();

            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
            {
                var viewName         = viewType.FullName;
                var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;
                var viewModelName    = String.Format(CultureInfo.InvariantCulture, "{0}Model, {1}", viewName, viewAssemblyName);
                return(Type.GetType(viewModelName));
            });

            Bootstrapper bs = new Bootstrapper();

            ViewModelLocationProvider.SetDefaultViewModelFactory((type) =>
            {
                return(bs.Container.Resolve(type));
            });

            bs.Run();
        }
Esempio n. 21
0
 private void App_OnStartup(object sender, StartupEventArgs e)
 {
     ViewModelLocationProvider.SetDefaultViewModelFactory(x => this.Container.Resolve(x));
     this.Container.RegisterType <IFileService, FileManager>();
     this.Container.RegisterType <IFileExportService, FileExportManager>();
     this.Container.Resolve <MainWindow>().Show();
 }
Esempio n. 22
0
        /// <summary>
        /// Вызывает событие <see cref="Application.Startup" />.
        /// </summary>
        /// <param name="e">Объект <see cref="StartupEventArgs" />, содержащий данные события.</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            DispatcherUnhandledException += OnDispatcherUnhandledException;

            DbValidator.VerifyDatabase();

            base.OnStartup(e);

            var initer = ViewModelInitializer.Instance;

            MainContainer.Instance.RegisterType <IDbEndPoint, DbEndPoint>();
            MainContainer.Instance.RegisterType <IDbContextFactory, DbContextFactory>();
            MainContainer.Instance.RegisterInstance <IUnityContainer>(MainContainer.Instance);
            MainContainer.Instance.RegisterInstance <AllFloorsProvider>(AllFloorsProvider.Instance);
            MainContainer.Instance.RegisterInstance <IFloorsProvider>(nameof(SectionType.Furniture), AllFloorsProvider.Instance.FurnitureFloorsProvider);
            MainContainer.Instance.RegisterInstance <IFloorsProvider>(nameof(SectionType.Hospital), AllFloorsProvider.Instance.HospitalFloorsProvider);

            ViewModelLocationProvider.SetDefaultViewModelFactory(instancesCache.GetOrCreateInstance);
            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(viewMappingCache.GetViewModelType);

            this.Subscribe <MessageShowFlatIndications>(OnShowFlatIndicationsRequest);
            this.Subscribe <MessageShowFloorIndications>(OnShowFloorIndicationsRequest);
            this.Subscribe <MessageShowNotes <SubjectEntityViewModelBase> >(OnShowNotesRequest);
            this.Subscribe <MessageShowPhotos <SubjectEntityViewModelBase> >(OnShowPhotosRequest);
        }
Esempio n. 23
0
        protected override void InitializeShell()
        {
            base.InitializeShell();
            ViewModelLocationProvider.SetDefaultViewModelFactory(x => Container.Resolve(x));

            Application.Current.MainWindow = (Window)Shell;
            Application.Current.MainWindow.Show();
        }
Esempio n. 24
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public App()
        {
            // ViewModel をインスタンス化するデフォルトメソッドを指定
            ViewModelLocationProvider.SetDefaultViewModelFactory((type) => Container.Resolve(type));

            Navigation    = new NavigationPage(new TopPage());
            this.MainPage = Navigation;
        }
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.container = new UnityContainer();
            this.container.RegisterType <AppContext>(new ContainerControlledLifetimeManager());
            this.container.RegisterType <EventAggregator>(new ContainerControlledLifetimeManager());

            ViewModelLocationProvider.SetDefaultViewModelFactory(t => this.container.Resolve(t));
        }
Esempio n. 26
0
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();

            ViewModelLocationProvider.SetDefaultViewModelFactory((type) => Container.Resolve(type));

            Container.RegisterType <IShellService, ShellService>(new ContainerControlledLifetimeManager());
        }
Esempio n. 27
0
        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            ViewModelLocationProvider.SetDefaultViewModelFactory((type) =>
            {
                return(Container.Resolve(type));
            });

            // Loading common modules

            Type LInstModuleType = typeof(LInst.LInstModule);

            moduleCatalog.AddModule(
                new ModuleInfo()
            {
                ModuleName = LInstModuleType.Name,
                ModuleType = LInstModuleType.AssemblyQualifiedName
            });

            Type InfrastructureModuleType = typeof(Infrastructure.InfrastructureModule);

            moduleCatalog.AddModule(
                new Prism.Modularity.ModuleInfo()
            {
                ModuleName = InfrastructureModuleType.Name,
                ModuleType = InfrastructureModuleType.AssemblyQualifiedName
            });

            Type ControlsModuleType = typeof(Controls.ControlsModule);

            moduleCatalog.AddModule(
                new ModuleInfo()
            {
                ModuleName = ControlsModuleType.Name,
                ModuleType = ControlsModuleType.AssemblyQualifiedName
            });

            // Initializing modules to be loaded on demand

            Type AdminModuleType = typeof(Admin.AdminModule);

            moduleCatalog.AddModule(
                new Prism.Modularity.ModuleInfo()
            {
                ModuleName         = AdminModuleType.Name,
                ModuleType         = AdminModuleType.AssemblyQualifiedName,
                InitializationMode = Prism.Modularity.InitializationMode.OnDemand
            });

            Type InstrumentModuleType = typeof(Instruments.InstrumentsModule);

            moduleCatalog.AddModule(
                new ModuleInfo()
            {
                ModuleName         = InstrumentModuleType.Name,
                ModuleType         = InstrumentModuleType.AssemblyQualifiedName,
                InitializationMode = InitializationMode.OnDemand
            });
        }
Esempio n. 28
0
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();

            ViewModelLocationProvider.SetDefaultViewModelFactory((type) =>
            {
                return(Container.Resolve(type));
            });
        }
        protected override Task OnInitializeAsync(IActivatedEventArgs args)
        {
            EventAggregator = new EventAggregator();
            _logger         = new Logger();

            ViewModelLocationProvider.SetDefaultViewModelFactory(CachingFactory);

            return(base.OnInitializeAsync(args));
        }
Esempio n. 30
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            ViewModelLocationProvider.SetDefaultViewModelFactory(x => this.Container.Resolve(x));
            var vm   = new MainWindowViewModel();
            var main = this.Container.Resolve <MainWindowView>();

            main.DataContext = vm;
            main.Show();
        }