Exemple #1
0
        public MainWindow()
        {
            InitializeComponent();

            var container = new UnityContainer();

            container.AddNewExtension <UnityPropertyContainerExt>();
            container.MarkPropertyContainer <ViewModel>();
            container.MarkPropertyContainer <ViewModelWithErrorInfo>();
            container.MarkPropertyContainer <ViewModelWithDirtyTracker>();
            container.RegisterType <IPropertyDirtyTracker, PropertyDirtyTracker>();

            var vm = ViewModel = container.Resolve <ViewModel>();

            vm.HookChange(o => o.Name, HandleNameChanged);
            vm.HookChange(o => o.Age, HandleAgeChanged);
            vm.HookChange(HandlePropertyChanged);

            var vmWithErrorInfo = ViewModelWithErrorInfo = container.Resolve <ViewModelWithErrorInfo>();

            vmWithErrorInfo.HookChange(o => o.Name, HandleNameChanged);
            vmWithErrorInfo.HookChange(o => o.Age, HandleAgeChanged);
            vmWithErrorInfo.HookChange(HandlePropertyChanged);

            var viewModelWithDirtyTracker = ViewModelWithDirtyTracker = container.Resolve <ViewModelWithDirtyTracker>();

            viewModelWithDirtyTracker.HookChange(o => o.Name, HandleNameChanged);
            viewModelWithDirtyTracker.HookChange(o => o.Age, HandleAgeChanged);
            viewModelWithDirtyTracker.HookChange(HandlePropertyChanged);

            DataContext = this;
        }
Exemple #2
0
        private static T CreateViewModel <T>() where T : class
        {
            var container = new UnityContainer();

            container.AddNewExtension <UnityPropertyContainerExt>();
            container.MarkPropertyContainer <T>();

            return(container.Resolve <T>());
        }
        public void Task_01_Resolve_04_Already_Registered()
        {
            var container = new UnityContainer();

            container.AddNewExtension <UnityPropertyContainerExt>();
            container.MarkPropertyContainer <ViewModel>();
            container.RegisterType <ViewModel>();

            var vm = container.Resolve <ViewModel>();

            Assert.That(vm.GetType() == typeof(ViewModel));
        }