protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            _container = new UnityContainer();
            _container.RegisterInstance<IUnityContainer>(_container);
            var locator = new UnityServiceLocator(_container);
            ServiceLocator.SetLocatorProvider(() => locator);

            _container.RegisterType<UserProvider>(new ContainerControlledLifetimeManager());

            _container.RegisterType<IChildViewModelManager, ChildViewModelManager>(new ContainerControlledLifetimeManager());
            _container.RegisterType<UserDetailsViewModel>(new ContainerControlledLifetimeManager());
            _container.RegisterType<UserListViewModel>(new ContainerControlledLifetimeManager());

            var mappingResolver = new MappingViewTypeResolver();
            mappingResolver.RegisterTypeMapping<UserDetailsView, UserDetailsViewModel>();
            mappingResolver.RegisterTypeMapping<UserListView, UserListViewModel>();
            mappingResolver.RegisterTypeMapping<UserDetailsWindow, UserDetailsWindowViewModel>();
            _container.RegisterInstance<IViewTypeResolver>(mappingResolver);
            var mainVM = _container.Resolve<MainWindowViewModel>();
            mainVM.Initialize();

            var mainWindow = new MainWindow();
            mainWindow.DataContext = mainVM;
            mainWindow.Show();
        }
示例#2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            _container = new UnityContainer();
            _container.RegisterInstance <IUnityContainer>(_container);
            var locator = new UnityServiceLocator(_container);

            ServiceLocator.SetLocatorProvider(() => locator);

            _container.RegisterType <UserProvider>(new ContainerControlledLifetimeManager());

            _container.RegisterType <IChildViewModelManager, ChildViewModelManager>(new ContainerControlledLifetimeManager());
            _container.RegisterType <UserDetailsViewModel>(new ContainerControlledLifetimeManager());
            _container.RegisterType <UserListViewModel>(new ContainerControlledLifetimeManager());


            var mappingResolver = new MappingViewTypeResolver();

            mappingResolver.RegisterTypeMapping <UserDetailsView, UserDetailsViewModel>();
            mappingResolver.RegisterTypeMapping <UserListView, UserListViewModel>();
            mappingResolver.RegisterTypeMapping <UserDetailsWindow, UserDetailsWindowViewModel>();
            _container.RegisterInstance <IViewTypeResolver>(mappingResolver);
            var mainVM = _container.Resolve <MainWindowViewModel>();

            mainVM.Initialize();

            var mainWindow = new MainWindow();

            mainWindow.DataContext = mainVM;
            mainWindow.Show();
        }