How much does the Windows Community MVVM Toolkit REALLY help us?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I've gotten tons of comments telling me to try out the windows Community mvvm toolkit so let's talk about it now suppose you're building a net mvvm project it doesn't matter if it's a Mali application or a WPF application you're just trying to build your dream app to solve some kind of problem but one of the first things we need to do is add some mvvm Essentials to our project so you might create a base fee model that implements I notify property changed you might create a base command that implements the I command interface and maybe you spin up some navigation infrastructure so that you can easily switch between pages in your application but the issue here is that this is all boilerplate and we need to write this boilerplate ourselves and that takes time away from focusing on building our dream application from solving the problems that we want to solve and from writing out our domain logic and sometimes we even have to write out this boilerplate across multiple projects so you might spin up a new project later on and rewrite the same exact mvvm Essentials that you wrote in your previous project now imagine a world where we didn't have to write this boy played ourselves and there was a standard solution where we could just bring the nvvm essentials into our project via a package and that's where the windows Community mvvm toolkit comes in it helps us with this boilerplate it lays down the essentials so that we can focus on building our dream application so how much does the windows Community mvvm toolkit really help us let's see what it has to offer so for one it offers an observable object that implements the I notify property changed interface so the key here is that we don't need to implement our own base V model whenever we spin up a.net mvvm project we can inherit from observable object and use the standard one property changed method and notify our UI whenever our properties change it also offers a relay command implementation and an async relay command implementation so the way relay commands work is we can pass in a callback to the Constructor of these commands and whenever these commands get executed it's simply going to execute whatever call callback we passed in the mvvm toolkit also offers a bunch of messaging infrastructure so these Messengers offer communication between components such as between view models and these Messengers are where the observable recipients come into play so instead of a view model inheriting from observable object it can inherit from observable of recipient and observable recipient allows us to override some life cycle methods such as unactivated and undeactivated and most importantly these lifecycle methods own the observable recipient are perfect for subscribing The Messengers and cleaning up subscriptions the mbvm toolkit exposes an observable validator that extends observable objects and provides an implementation for inertified data error info so it exposes a bunch of helpful methods for dealing with validation related to I notified data error info and most importantly it allows us to use validation attributes on our properties so instead of doing validation in massive Setters we can just use validation attribute shoots and apply that validation declaratively and finally speaking of attributes I almost forgot about this but the mvvm toolkit provides some crazy helpful attributes so for one we can use the observable property attribute to turn any field into a property that raises property change and this cuts down on a bunch of boilerplate we no longer need Snippets to write out all this boilerplate for ourselves we can just use an attribute there's also a relay command attribute so this attribute we can throw on top of any function and it'll turn that function into a relay command that we can bind to from our UI this attribute is arguably even more exciting because we can just focus on writing out functions and building out our domain logic and not even have to worry about turning those into commands we can just use the relay command attribute and have the command so these are the exciting Parts about the mvvm toolkit but I do have some concerns for one I was concerned that the observable object didn't offer any life cycle methods so for one I typically have my base fee models inherit or Implement I disposable so that I can dispose of them when I'm done with them and clean up any event subscriptions that took place in the view model on the contrary I suppose I could just use the observable recipient instead and rely on the undeactivated method to do any Cleanup in my view models the other concern I had is I'm not particularly a fan of relay commands I like to use class commands instead where I have a class that implements the I command interface and contains all of the command logic that I want to execute the issue with relay commands is I feel like they end up bloating the viewmodel whereas with class commands all the logic related to the command is set aside in a different class I feel like class commands are more reusable and it's easier to find the command logic just browsing through the file structure rather than having to dig into viewmodels however the relay command attribute where you can turn any function into a relay command is really making me rethink this opinion here if I am still worried about bloat with relay commands I could just have a function in my view model that delegates to a service that executes the command logic and then Mark that function with the relay commands and I shouldn't have any Bluetooth then the next concern I had at first was with the messenger so for some reason at first I feel like the messenger was some kind of State Management solution but in reality the messenger is just a piece that works with your State Management solution so whenever your estate changes you can leverage a messenger to push out State changes to view models that have subscribed it's somewhat like a more fluent abstraction on top of.net events there's also a cool feature with Messengers where subscribers can request data from the data source I could see this being useful related to State Management so imagine you instantiate a viewmodel that viewmodel could request data from the store via the messenger the final concern I had was that there's no built-in navigation infrastructure or State Management solution and looking back this is understandable because hey this is just the library to help us build old mvvm projects it's not a framework that's enforcing some kind of application infrastructure plus dot Maui already has navigation built in which I'm super excited about by the way so overall I would recommend trying out the windows community and vvm toolkit even if there are some parts that you don't like about the toolkit keep in mind you don't have to use everything you can just choose what you need to help you build your application that said I'd still recommend understanding mvvm Essentials such as the I notify property changed interface so that you understand what's going on under the hood of the library and if you ever need to spin up your own custom infrastructure you'll understand how to do that but overall give the windows Community mvvm toolkit a try on your next net mvvm application so that you no longer have to write your own mvvm boilerplate and you can focus on building your dream application [Music] [Music] foreign
Info
Channel: SingletonSean
Views: 10,106
Rating: undefined out of 5
Keywords: wpf, programming, visual, studio, xaml, custom, control, generic, system, line, display, dispatcher, timer, template, binding, behavior, c#, how, to, series, easy, time, reusable, package, design, part, dependency, property, event, code, framework, register, static, state, default, clean, view, style, scroll, component, command, async, handling, action, task, void, model, layout, user, box, mvvm, reuse, dotnet, cli, pack, cmd, git, dev, actions, render, react, vue, next, js, windows, community, toolkit, inotifypropertychanged, observable, message, messaging, relay
Id: KVr7_QtlcmI
Channel Id: undefined
Length: 7min 2sec (422 seconds)
Published: Tue Mar 21 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.