@@debeerpaul I can't remember if I ever did implement any MVVM, but the company was satisfied with the website. I like Blazor, as a developer, but I think the trade offs on wasm (long startup times) and signalr (weird rendering, re-rendering issues, reconnection issues) don't really draw me back to using it on other projects. I did play around with ssr and it caught my attention for a bit. I think ssr Blazor with signal r in select places might be wonderful but I haven't given it a fair shake. Generally now I just use razor pages with some javascript to do what I need. Note I'm not making big fancy web apps. Mostly just admin panels.
@@liquidpebbles Thanks yes we are experiencing the exact same issues with the signalR websockets taking long to update appstates etc on slow connections.
What do we actually gain from the additional effort? We could inject a different version of the vm in testing maybe, but what is the return on investment here?
Nice tutorial. Question - this version of MVVM looks so much different (and more intuitive I'd add) then the traditional MVVM (INotify..., Set, OnPropChange...; etc.). Can you explain why you implemented MVVM this way as opposed to the more traditional way? Also, I noticed that doing it your way you cannot call StateHasChanged in the ViewModel due to an issue with something called a RenderHandle. Is there a solution that exists for that without putting the code in the @code { } section or in a code-behind?
Thanks Ryan. This implementation is particular to Blazor, which does not require INotifyPropertyChanged. As Carl recalls, he added an event handler which you can hook to call StateHasChanged.
I always use INotifyPropertyChanged in Blazor. How is your UI notified of changes? Even today with .Net 6 if i forget to propertychanged a value then the UI does not know about it.. especially with SignalR
6:55 mistake in NewCustomer(). Setting new Id as Count +1 is not a good idea. if You delete first customer an then add new one - you'll get two ( or even more ) customers with id = 3
Hi Paul. Thanks for the question. The answer is Basic Binding. Everything in the ViewModel is a property or a Task - all done with binding, so StateHasChanged happens automatically. But, in the case where it doesn't work, you could expose an OnStateHasChanged event, meaning you'd have one code-behind event handler that called StateHasChanged.
On Monday I'll show you how to raise an event in a business model when a property changes so the viewmodel can do whatever it needs to do to update the view.
Hi Carl, how do I use Parameters with a ViewModel? My view defines a parameter to receive data from another component how do I pass that value to initialise the ViewModel?
What is the benefit of using this versus a nice razor.cs file that does all the work? I usually have a simple DTO, a .razor blazor page and a razor.cs backing file... isn't that essentially doing the same thing?
yes now with records it's also less time consuming to create those Dtos since they are immutable. I guess it depends on how good you want to do the job lol.
this is what i call professionalism
Ive got to go clean up my super scrappy website to use MVVM now. Thanks so much for the very straight forward explanation and walk through!
How did it work for you? Whats your take on blazor and are you still using it?
@@debeerpaul I can't remember if I ever did implement any MVVM, but the company was satisfied with the website. I like Blazor, as a developer, but I think the trade offs on wasm (long startup times) and signalr (weird rendering, re-rendering issues, reconnection issues) don't really draw me back to using it on other projects.
I did play around with ssr and it caught my attention for a bit. I think ssr Blazor with signal r in select places might be wonderful but I haven't given it a fair shake.
Generally now I just use razor pages with some javascript to do what I need. Note I'm not making big fancy web apps. Mostly just admin panels.
@@liquidpebbles Thanks yes we are experiencing the exact same issues with the signalR websockets taking long to update appstates etc on slow connections.
What do we actually gain from the additional effort? We could inject a different version of the vm in testing maybe, but what is the return on investment here?
Thanks you so much for this Chris - I appreciate you so much, for this series of yours! Toot your horn, brother!
Nice tutorial. Question - this version of MVVM looks so much different (and more intuitive I'd add) then the traditional MVVM (INotify..., Set, OnPropChange...; etc.). Can you explain why you implemented MVVM this way as opposed to the more traditional way? Also, I noticed that doing it your way you cannot call StateHasChanged in the ViewModel due to an issue with something called a RenderHandle. Is there a solution that exists for that without putting the code in the @code { } section or in a code-behind?
Thanks Ryan. This implementation is particular to Blazor, which does not require INotifyPropertyChanged. As Carl recalls, he added an event handler which you can hook to call StateHasChanged.
I always use INotifyPropertyChanged in Blazor. How is your UI notified of changes? Even today with .Net 6 if i forget to propertychanged a value then the UI does not know about it.. especially with SignalR
6:55 mistake in NewCustomer(). Setting new Id as Count +1 is not a good idea. if You delete first customer an then add new one - you'll get two ( or even more ) customers with id = 3
Hi Carl thanks for the great vid. How is the UI notified of property changes in the ViewModel?
Hi Paul. Thanks for the question. The answer is Basic Binding. Everything in the ViewModel is a property or a Task - all done with binding, so StateHasChanged happens automatically. But, in the case where it doesn't work, you could expose an OnStateHasChanged event, meaning you'd have one code-behind event handler that called StateHasChanged.
On Monday I'll show you how to raise an event in a business model when a property changes so the viewmodel can do whatever it needs to do to update the view.
Hi Carl, how do I use Parameters with a ViewModel? My view defines a parameter to receive data from another component how do I pass that value to initialise the ViewModel?
Hi Clement. One way is to create an Initialize method on the ViewModel, that you can call from the view.
Any plans to have a video that implements the DevExpress Blazor Data Grid control?
Hi Daniel, have you seen this video?
ua-cam.com/video/VXqxKFjZLwk/v-deo.html
If you need help with DevExpress Blazor Data Grid and MVVM, please contact our support team and they can help you: devexpress.com/ask
As a matter of fact, yes. I plan on covering the Dx data grid control later this year.
thanks Carl. Very helpful! I enjoy the videos.
Excellent ! 😀
Thank you~! you are the best!!
What is the benefit of using this versus a nice razor.cs file that does all the work?
I usually have a simple DTO, a .razor blazor page and a razor.cs backing file... isn't that essentially doing the same thing?
Separation. A viewmodel is a class that stands on its own. A razor.cs file is tightly coupled to the markup.
@@carlfranklin7894 tnx for the clarification, I'm gonna think about using this technique.
LOOK MA NO CODE BEHIND!
Cracke me up good and not the only time..
Anyone using this in production?
legend
I worked with a Mike Easter...
I thought await Task.Yield() is better than await.TaskDelay(0)
Carl, shouldn't we use a DTO for a model than an Entity from the backend? This way we're not exposing a model to the client.
yes now with records it's also less time consuming to create those Dtos since they are immutable. I guess it depends on how good you want to do the job lol.