Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transactional objects in .NET [closed]

In user interfaces there is often a need to implement a cancel button when editing some entities. In WPF it would be nice if you could make your view model transactional. I will try to explain a little bit more in detail what I mean:

The view model is connected to the model and exposes data in a way that's easier to handle for the view (utilizing data binding). Changes to the view model result in changes in the model. However, if there is a cancel button you usually don't want to perform the changes immediately on the model, so I think of some kind of buffering changes. When you commit the changes, there are being transferred to the model, otherwise they are deleted.

Right now I have implemented a solution that creates a proxy of the view model which is bound to the view instead of the real view model. The proxy is not connected to the model but records changes to properties and method calls by using interceptors. There is a submit method which applies the invocations on the real view model. I think that's quite a good solution but it is still quite buggy (if the view model contains collections and so on).

I'm looking for a framework which does this kind of stuff. Are there any out there?

Best Regards,
Oliver Hanappi

like image 779
Oliver Hanappi Avatar asked Jun 12 '26 02:06

Oliver Hanappi


2 Answers

You can take a look at the Cinch MVVM Framework by Sacha Barber.

It offers "IEditableObject usage to store/restore object state on edit / cancel edit"

like image 152
japf Avatar answered Jun 13 '26 17:06

japf


BindingGroups aren't just for Binding validation, you can use a BindingGroup's BeginEdit, CommitEdit, and CancelEdit to enable transactional logic. If you're a pure MVVM type there's one thing that might be a problem for you - you will most likely get some code-behind in your views - otherwise it works like a charm.

like image 22
Bryan Anderson Avatar answered Jun 13 '26 15:06

Bryan Anderson