ValidateBusinessRules is called when viewModel already closed?

Topics: Issues / bugs
Jul 19, 2012 at 2:29 PM
Edited Jul 19, 2012 at 2:30 PM

From within a CustomersViewModel I open a CustomerViewModel using ShowDialog of the uiVisualizerService.

After ShowDialog returns I do a commit of my UnitOfWork. However, when this happens I see that the ValidateBusinessRules method of the CustomerViewModel is called again. I would suspect that this would no longer exist since the dialog has finished?

It's not a real problem, I now check the property IsClosed in ValidateBusinessRules so I don't validate when the viewmodel is closed. But I would like to understand why this is happening, so any enlightenment would be appreciated :)

The code in CustomersViewModel is as follows:

                using (TimeLogUnitOfWork unitOfWork = new TimeLogUnitOfWork())
                    Customer customer = new Customer();
                    CustomerViewModel viewModel = new CustomerViewModel(customer);
                    IUIVisualizerService uiVisualizerService = GetService<IUIVisualizerService>();
                    if (uiVisualizerService.ShowDialog(viewModel) == true)
                        refreshData = true;


As soon as unitOfWork.Commit is called I see that ValidateBusinessRules of viewModel is still called.

Jul 19, 2012 at 7:40 PM

If I am correct, the Validate is not longer called when the ViewModel is closed. Maybe it is called on the model? I will double check this.

Jul 20, 2012 at 7:24 AM

'My' ValidateBusinessRules method resides in the ViewModel and not in the model. The model (naturally) has no reference to the view model.

Jul 20, 2012 at 8:55 AM

I just set SuspendValidation = true in closeviewmodel. Hopefully it will not break anything.

Jul 20, 2012 at 9:31 AM

I'm still wondering why the viewmodel validation is called when I commit the model....

Jul 20, 2012 at 10:13 AM

Just released a new version via nuget. Try again please.

Jul 20, 2012 at 10:31 AM

The 'fix' seems to work (but still wondering why it is at all necessary :) )

Jul 20, 2012 at 11:01 AM

In the end, the viewmodelbase is just a dataobjectbase. This validates as soon as a property changes. Now, it will just ignore properties and stop validating when the VM is closed.