MVVMS... A Better MVVM? Model-View-ViewModel-Services Explained

  Рет қаралды 31,604

James Montemagno

James Montemagno

Күн бұрын

Пікірлер: 126
@_SkyDancer
@_SkyDancer 8 ай бұрын
Finally I almost understood this pattern, the only thing that nobody mentions is the SERVICE! Nobody tells about services but this is the key for understanding MVVM pattern! With knowing about the service responsibility everything makes sense now because now you can understand how you actually generate your incoming and outcoming data like literally, the bytes of information. Thank you fir this video.
@johnallcock5582
@johnallcock5582 Жыл бұрын
the suggestions made in this video about which bars of MVVM(S) make easily the most sense on this subject than I have found anywhere else. Well done.
@keigezellig
@keigezellig 9 ай бұрын
I am doing some MAUI development lately (and have previous experience with MVVM) and this is EXACTLY the architecture i am using! 😊
@JamesMontemagno
@JamesMontemagno 9 ай бұрын
Great to hear!
@lucecarter
@lucecarter 2 жыл бұрын
As someone who regularly references your code samples to help me with various code scenarios, I instantly knew what the S stood for, before I even clicked on the video. You're officially an influencer! Hahah
@typhoonf6
@typhoonf6 2 жыл бұрын
Just wanted to say thanks James 👌started my foray into Xamarin and MAUI a year or so ago now, just as a personal hobby. Your videos/repos have been invaluable and it's always nice to learn the right way to do something the first time. Cheers!
@romanbohun9721
@romanbohun9721 2 жыл бұрын
I use practically the same pattern with some variations. Some layers could be added here but it depends on project size and complexity. Glad to see that you do the same things. Thank you for sharing!
@johnmcnulty1022
@johnmcnulty1022 2 жыл бұрын
What layers would you add Roman?
@krccmsitp2884
@krccmsitp2884 2 жыл бұрын
Makes total sense and it's as I always understood MVVM, thinking of the S(ervices) implicitly.
@jutyarr
@jutyarr 2 жыл бұрын
pretty nice as always James, for those who are new or confused, please watch "The Xamarin Show | Episode 13: MVVM Helpers" by james
@yosimadsu2189
@yosimadsu2189 2 жыл бұрын
Your MVVMS is actually the easiest way to approach app design. Thanks a lot 👍👍👍
@Ash_Industries
@Ash_Industries 9 ай бұрын
James, these videos have really inspired me to learn C#, Xmal, .Net, Maui......and now MVVMS lol
@vincentotieno9197
@vincentotieno9197 2 жыл бұрын
Thanks for this. I love MVVM and this is practically what I've always done. For serious applications I always separate the Models into their own project, which also includes the service interfaces (not their implementation).
@namelastname4077
@namelastname4077 2 жыл бұрын
yup. you can mock up your services much easier
@AlSavant
@AlSavant 2 жыл бұрын
"Model" can be understood in different contexts depending on which abstraction layer in your architecture you're describing. Typically people refer to it as the object model (the business logic of your application) or the data model (the state of the application). MVVM's take on model is that of the object model which is a higher abstraction layer than the data model which you present in your video. Their choice for that is deliberate: MVVM architecture describes the abstraction layers touching the View, it's an architectural pattern for creating applications with UI elements. "M" in MVVM is meant to be "just the business logic" implying there will also be services, factories, and of course data models, but the architecture does not care about describing the Model, it's up to each programmer to implement according to the needs of his/her application. MVVM more specifically is a reply to the MVC and MVP patterns, all of which describe the interaction between UI views and the model, and all of which refer to the object model as the definition of the "M" in their respective letter soups. Having said that, I have nothing bad to say about your way of setting up your projects, it's just that it's still MVVM, the M sucks up the S implicitly.
@ZeeshanAhmad-q8o
@ZeeshanAhmad-q8o 3 ай бұрын
Finally, I almost understand about MVVM. Thanks James.
@Armonica1967
@Armonica1967 Жыл бұрын
Very very good explanation!!! You have very clear concepts and you know how to transmit them. I have understood in your explanation what I have not understood in other tutorials. Congratulations!!! Greetings from Madrid, Spain!!! 👍👍👍👍😀😀
@HijiHakimaru
@HijiHakimaru 2 жыл бұрын
There are sooooo many "personal opinions" that I agree with and practice as well. I never really could quite name the "pattern" I use since it was just something that developed over time. Before this video, I was calling it a pseudo micro-services or service-oriented architecture with some MVC mixed in (because of using MVC project type, then Blazor WASM), which turned into a "maybe I really am using something more akin to MVVM since the controllers are "dumb controllers" that just forward the request to the server-side service implementation. In any case, MVVM-S it is:-). Thanks so much for another great informational video!
@gerryan9710
@gerryan9710 2 жыл бұрын
I also used that pattern and it was really easy to maintain.
@michaelrogers6935
@michaelrogers6935 4 ай бұрын
This really was awesome -- there ought to be a link to it on the official documentation page
@JamesMontemagno
@JamesMontemagno 3 ай бұрын
Thank you!
@schmidtlach
@schmidtlach 2 ай бұрын
Great idea. I tried to get my design to be similar to this. I came up with several ways, but James gave me a good example of how to do it.🤜🤛👏👏😁
@carlosdelvalle5417
@carlosdelvalle5417 2 жыл бұрын
I think it is pretty clear 😊. I’ll go refactor my current app right now!
@DanSiegel
@DanSiegel 2 жыл бұрын
So happy to see that you've finally seen the light with interfaces and services... but your MVVMS isn't some fancy new thing, it's just MVVM done exactly as it should be.
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
It is, but for anyone getting started I think it is nice to introduce this as a concept as someone new may just put logic right into the VM to call a web service and not think about abstracting it. Not everyone has been doing this stuff for 15 years.
@sebastianbusek2087
@sebastianbusek2087 2 жыл бұрын
Sure, you're right James, but it's the same as putting any logic inside the Controller (from MVC). I've been following you and Frank for about two years, and from the beginning, you, I mean you James, always have been against interface segregation. I've supposed you're not Unit testing your "services", but I've never heard that interface segregation makes sense, but you've decided not to use them, because... I'm glad that kind of video finally appears and may enlighten more devs.
@brandon-butler
@brandon-butler 2 жыл бұрын
I agree. Watched the video to see what the 'S' was and realized it's just MVVM :/
@usmcmckee
@usmcmckee 2 жыл бұрын
Great Video James. Looks like I need to update the MVVM Wiki page to say you invited MVVMS 🤣. It's such a simple concept the way you explained it. I am surprised it's not the official standard.
@logank.70
@logank.70 2 жыл бұрын
I guess I always took the `Model` part of MVVM to just mean "back end." I think for those who have been applying this pattern for long enough and are comfortable in it the "S" part of it just comes naturally (whether if you call it a service, or a manager, or whatever). I've been keeping an eye on Comet and I think the MVU (Model View Update) pattern is really interesting. It would be neat to do a compare/contrast (if you haven't already done one) on those two architectures.
@AlSavant
@AlSavant 2 жыл бұрын
I came in the comments looking for this reply.
@TuxCommander
@TuxCommander 2 жыл бұрын
Actually this is my approach since I develop WPF applications and it shakes me, when I see VMs with SQL or dbcontext inside.
@Ryan-tg1mx
@Ryan-tg1mx 2 жыл бұрын
Hey James, these tutorials are great for the entry into MVVM, but one thing I always wrestle with is scaling up for a more complicated architecture. Say you wanted to have a main page that contains several different components with their own types of data, do you go into nesting view models or do you flatten them into the one main view model? This might be a bad example, but say you split the monkeys app UI in half and have the list on top, and the bottom is a list of regions that filters based on a selection of monkey. I'd store the regions on their own, but when it comes to binding the UI, what's the best practice here? If the main page has its own viewmodel, do you ever bother making viewmodels for the unrelated data or do you only work off models once you get into the initial bound viewmodel? If you split the UI into two views, are you then binding each view to a model or do you wrap them with viewmodels at that point? I've not found a preferred way myself and was curious how others approach this. UI design issues aside, are people generally ok having a lot of model types inside one viewmodel?
@buddysnackit1758
@buddysnackit1758 Жыл бұрын
Thanks James. What I really wanted to find "somewhere" was a very straightforward "Create a MVVM skeletal project using WINUI 3." type of tutorial that is recent. Things I don't want to see: 1.) References to other toolkits or the example done in another kit with an explanation just do the WINUI 3 thing instead. 2.) Any explanation as to what MVVM is. 3.) Any explanation as to anything "alternative". I learn about the alternatives later. 4.) Things pre-created or partially started. I want to see all the things you do. 5.) The word Monkey should not be present...nor Snickerdoodle...nor supercalifragilisticexpialidocious (It is distracting.) What I think would be the most useful for me is to just watch you work while doing your very good communication while you are doing it. What would be ideal is to create a super simple application that searches a list of names and returns a phone number. Some of the small stuff trips me up (Because I have one of "those" type of brains.) So how are the filenames created? Do we still have to add them by hand and rename them. What about the folders? So I know you are just wondering who would need this and why. Don't ask. Just create it and we will all praise you. It can be as quick and dirty as you like as long as we see you do all the steps and we can follow along and have a working application. Sorry for being dense or not willing to watch 30 videos from years ago wondering if the content is still applicable. I guess I would just like a fresh starting point set to MVVM and WINUI3.
@petermurton4328
@petermurton4328 2 жыл бұрын
I have added a Service to handle the fetching and saving of a PropertyModel collection (From Azure BLOB Storage). This works fine and I thank you for the advice to move to MVVMS. I have a question: I have routines (MoveUp and MoveDown) that can reorder the PropertyCollection, do these belong in the Service?
@johnb2572
@johnb2572 2 жыл бұрын
Nice, very well explained thanks
@OneMassiveMan
@OneMassiveMan Жыл бұрын
You’re the best James I watch all your videos
@JamesMontemagno
@JamesMontemagno Жыл бұрын
@technics6215
@technics6215 2 жыл бұрын
James, if the Model works just as data transfer/storage object (you are using kind of POCO class for Monkey) - where should I put my application logic? I usually put it in the Model. I should create services for bussiness/logic layer?
@DTGxliljarhead
@DTGxliljarhead 2 жыл бұрын
Awesome video! Next, could you make a video explaining how to add logic to Xamarin Forms Binded ListView objects. For example, if I am making a bank account app that tracks transactions, how could I make a certain label red if an amount is withdrawn or green if an amount is deposited. Also how could I bind the transaction type to a label that displays an icon based on the transaction type. For example, if the transaction was a web withdrawal show a credit card font icon, if the transaction was a cash withdrawal show a bank font icon, if the transaction was a web deposit show a globe icon, or if the transaction is a cash deposit show a dollar bill icon. I am yet to find a video that will help me accomplish this and I'm sure it will help plenty of other self taught developers like me!
@Moosa_Says
@Moosa_Says 2 жыл бұрын
Exact pattern that i use but i always apply an Interface on a service, for testability :)
@Speede04
@Speede04 Жыл бұрын
I would love to see tutorial about opening/creating new window in MVVM architecture. It is pain in the ass, there are so many opinions in the internet for proper way to do it.
@megaman2016
@megaman2016 2 жыл бұрын
I look as mvvm as a front end architecture pattern. Depending on the problem to be solved you can have a SOA or plugin/micro kernel or other layers and architecture patterns underneath.
@RexTorres
@RexTorres 2 жыл бұрын
This is basically what I have been doing in Android, but instead of "services," I have "repositories," which represent "the single source of truth" and, as with your services, contain the logic for handling data from the internet/database/etc. So, if I were to name the pattern, it would be MVVMR. 😅
@olagisrarikis
@olagisrarikis 2 жыл бұрын
One quick question: Does "Visual Studio for ARM 2022" have .NET Maui workload on the roadmap?
@antisnufff
@antisnufff 8 ай бұрын
I think, nowadays the most struggle is to hande navigation and had a good workflow. I implemented a Controller Class to decouple this. So i have now MVVMSC, eheh
@blackbeans3112
@blackbeans3112 2 жыл бұрын
Can I apply it in web development?
@OldShoolGames
@OldShoolGames Жыл бұрын
In case of reusable components that we want to use across multiple views, should we use MVVM for that as well ? Should the bigger viewmodels directly reference the viewmodels of these reusable components ?
@chrissmith9725
@chrissmith9725 Жыл бұрын
Really helpful thankyou JM
@JamesMontemagno
@JamesMontemagno Жыл бұрын
Glad it helped out
@MrSikesben
@MrSikesben 2 жыл бұрын
Thanks James clear now to me, Is it possible to use code generated by nswag for API as apart of MAUI code base. Thanks once again for the gems
@hastifallah73
@hastifallah73 2 жыл бұрын
Hi. It would be so great if you make a video about comparison between flatter and Maui
@TornTech1
@TornTech1 2 жыл бұрын
What are your thoughts about the dependency of the model spanning all the way from deserialisation inside of the service to binding on the view? I get that it makes it easier, your not having to do a mapping exercise. But it just feels like the model should be owned by the view and an identical DTO type model used in the service for deserialisation. What if the json structure was to change? Now your views model is pretty much bound to the backend JSON structure?
@neralem
@neralem 2 жыл бұрын
You showcased the CommunityToolkit preview that offers mvvm with source generators. Can you tell us how to use this with dedicated models?
@dreamdancer8212
@dreamdancer8212 2 жыл бұрын
Thanks for this, as usual, great explanation. But one question puzzles me. Isn´t that architecture in a way an Anemic domain model? Or would you rather say we are not really talking of Domain Models in this case but simple Data structures to pass data around - a bit like a date transfer object. And if your application would need a real business logic - where would you put it? I personally struggle with this question a lot. It would be great to hear your view
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
Well if it is processing the data just for the viewmodel i think fine to put it in there, but if hitting external services such as HTTP/DataBase/ETC I would put it not in there. Would probably need an example, but in general... whatever you do an pick is fine ;)
@Adam-ce5mq
@Adam-ce5mq 2 жыл бұрын
I also struggle a bit with what exactly people consider the model to be in MVVM. I'm not sure there's a definitive answer. I generally don't use my domain models as the model and, as James has done here, tend to create POCOs to do the job - certainly in an application of any size and complexity. When using domain models in MVVM I feel I always end up muddying their clarity and purpose by introducing concerns that feel primarily, if not exclusively, related to the UI.
@spaprune
@spaprune 2 жыл бұрын
Thanks! Your videos are helping this 38+ year coder get up to speed with this latest YAF (yet another framework). Do you have recommendations for authentication and managing session state? In a “roll your own” Auth scheme, which is more likely in private enterprise line-of-business apps, I was thinking of simply setting that up as just another set of classes through mvvms. I see 3rd party services (like auth0) but I can’t see how I’d reconcile that with an internally managed authorized user list, and the services don’t seem to address session state management.
@maheshkumbhar4216
@maheshkumbhar4216 2 жыл бұрын
Hi @James, What is future of Xamarin UiTest with MAUI ????
@zarokoshin4090
@zarokoshin4090 2 жыл бұрын
Great Video !! It would be cool if you make a video about Content Provider to share SQLite database across apps (locally)…
@btigenie
@btigenie 2 жыл бұрын
Another awesome video! Not just for the content but because of the way you explain and how logical everything is. Your videos should be a staple in every CS Curriculum in college! Question. I usually put all my EF database "stuff" in a separate project and reference it in my main app. I also usually have a Repository project as well if it will have a lot of custom methods, etc. In your "S" pattern, would you still use the services to call out to the Repository project or start phasing out the Repository and store all that in the Services section?
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
I now consider the Repository and Service the same thing. I don't like to add that additional layer on. NO real reason IMHO.
@btigenie
@btigenie 2 жыл бұрын
@@JamesMontemagnoUnless you have other layers that might need to access the DB, you put everything in the Service layer?
@Jake-iw3tl
@Jake-iw3tl 2 жыл бұрын
I still remember a time before you looked like hippie Tech Jesus 😄 And how do you not have more subscribers? 😮
@EnriqueThedy
@EnriqueThedy 2 жыл бұрын
Hello James! from Rosario, Argentina. Thanks for all of your videos, you're a great communicator. I'm "ready" to advance in the future to MAUI and WinUI but for now working in WPF yet. Could you please take a few minutes to explain how to use the hosting facilities of NET into a WPF app? i.e logging, DI, hosted services...etc. I have an idea how I could do it (basically starting from a console project), but surely you could describe it in a more formal way. Thank you ;very much!
@deltaphilip8611
@deltaphilip8611 2 жыл бұрын
The view is the xaml with no code behind or little? Who is the navigation boss? The view, or the view model? I am leaning blazor, is MVVMS applicable?
@laurolnunes
@laurolnunes 2 жыл бұрын
Hello James! =) Could you explain about OnPropertyChanged in BindableObjects? I'm trying to bind three properties in cascade, but when I call the first OnPropertyChanged of this cascade, it passes twice and assigns null to the last property. Do you know why this is happening?
@jagadishwarballa
@jagadishwarballa 2 жыл бұрын
I see errors in 2 way binding in MAUI. One I reported to Microsoft. I see couple of more. Data binding is working only for the current page. If we make changes in detail page and comeback to previous page , we will still see the old details in main page.
@elemiliio4582
@elemiliio4582 2 жыл бұрын
Hey James. Really nice video, just caught up on MAUI recently, had been working on WPF for a while. I think we share a very very similar opinion on how MVVM should work. I have a question for you! In your opinion, what are the advantages/disadvantages of putting services in an interface? Also do you declare them as singleton in the builder? Thanks man
@moranlg
@moranlg Жыл бұрын
I am not James, But I will try to answer your questions (from my point of view) First question: As usual, you will need to put your service under the interface in the next scenarios: 1. For testing another class that depends on your service - You would like to mock your service in this case 2. Different implementations for the same functionality 3. If you want to reduce the references dlls from your program - Assuming that the service is defined in another dll If you are not planning that, then an interface will not be required. The second question (Service as a singleton) 1. When you need to synchronize (lock) access to a shared resource (for example). 2. When performance is important, the pattern will allow you to create the instance only once. 3. When you want to communicate between view models, an event aggregator is not an option If none of the above is required, I strongly suggest avoiding the singleton pattern for various reasons among them: 1. It "enforces" its lifetime on injected services 2. Assume that you have for example tabs in your application, and the user is currently viewing the first tab. why are the services which are related to the second tab should live at all...
@TaoriUTS
@TaoriUTS 2 жыл бұрын
10:13 you are creating a http client. Is HttpClientFactory not a thing in the MAUI sdk? Afaik creating individual http clients instead of recycling them throughout an application per host domain can cause socket exhaustion on the far end.
@cbradbaer
@cbradbaer 2 жыл бұрын
Hi James, thanks for making such a clear and concise video. Side note question: I noticed in your code you are now using [RelayCommmand] instead of [ICommand] from the Toolkit's MVVM helpers. Can you explain the difference? Thanks.
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
Yes! In Preview 4 they renamed a few attributes -> github.com/CommunityToolkit/dotnet/releases/tag/v8.0.0-preview4
@marikselazemaj3428
@marikselazemaj3428 2 жыл бұрын
Totally agree
@junior.santana
@junior.santana 2 жыл бұрын
Hey James have you talked about exception handling yet? That could be a nice video
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
Will add to list for sure!
@gabrielheming
@gabrielheming 2 жыл бұрын
How about a more complex architecture as Hexagonal? I mean, not removing the MVVMS part, but splitting into projects as well. I am new to MAUI but came with an extensive background in API and major big projects. I often see small projects growing increasingly fast, and the single project or N-tiers solution becomes hard to maintain. Can be that true for MAUI projects, or do they benefit from the rule "smaller = better" (less complex)?
@marcinbalcerzyk84
@marcinbalcerzyk84 2 жыл бұрын
Hi. Does MVVMS makes sense for languages like Python?
@azgan123
@azgan123 2 жыл бұрын
Amazing hair! I can't believe you've been hiding it under a hat for so long.
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
It comes out on occasions ;)
@mikp1280
@mikp1280 2 жыл бұрын
Love your content! Can you suggest any forum for beginners? I have problems with maui in VS-preview which should be easy to solve. (Example: resolving from bindings in xaml)
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
Can checkout Q&A: docs.microsoft.com/en-us/answers/products/dotnet
@c0ward
@c0ward 2 жыл бұрын
I'm still curious around the use of the vanilla ObservableCollection - is it really good for performance to fire off an event for each monkey, or better to subclass and send one CollectionChanged once all monkeys are added?
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
I personally have an ObservableRangeCollection I use when adding a bunch of items. It is in my mvvm helpers library
@NK-xw4uu
@NK-xw4uu 2 жыл бұрын
Here is how I use ViewModel concept (which is different to your concept): Say there is User table and a UserAddress table. And there is a User and UserAddress model (entity framework). I will create a view model called vmUserAddress which contains fields from User and address model. Then I will create a service with method GetUserAddress(id) which will query the user and address tables and create a new instance of vmUserAddress and return it My controller will call that service method and the rerurnd vmUserAddress will be passed into the View.
@AdamsTaiwan
@AdamsTaiwan 2 жыл бұрын
I don't get the purpose of the AddSingleton, AddTransient, do you have a video on just these?
@abdalghanialbiek8999
@abdalghanialbiek8999 2 жыл бұрын
Can we use MVI pattern in C# project?? cause my brother told that he made an architecture for his flutter app using MVVM and MVI design patterns
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
Take a look at www.reactiveui.net/
@BrianLagunas
@BrianLagunas 2 жыл бұрын
You know I love you bro, but that's just plain MVVM 👍
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
It is, but for anyone getting started I think it is nice to introduce this as a concept as someone new may just put logic right into the VM to call a web service and not think about abstracting it. Not everyone has been doing this stuff for 15 years.
@BrianLagunas
@BrianLagunas 2 жыл бұрын
@@JamesMontemagno definitely. Thanks for taking the time to share and helping point people in the right direction.
@williamliu8985
@williamliu8985 2 жыл бұрын
Hi Brian, I haven't seen your update video for a long time, how are you doing?
@BrianLagunas
@BrianLagunas 2 жыл бұрын
@@williamliu8985 I’m doing great. Just really busy with my day job. Hoping to get back to videos soon though. Thanks for checking on me!
@williamliu8985
@williamliu8985 2 жыл бұрын
@@BrianLagunas Great! Your cool videos inspired me a lot in the WPF/MVVM, thanks a lot!!
@d3hlvi
@d3hlvi 2 жыл бұрын
Thank you for the nice video. I am new to MVVM. Please tell me how do you register services if you make it in a separate class library project.
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
Hello Riyaz! Thanks for subscribing and being a member! :) If you just add a reference to that project you can reference that service the same way.
@internetissue4548
@internetissue4548 2 жыл бұрын
What if i put Related Views and ViewModels together in a single Folder, rather than having a folder called "Views" and Another one called "ViewModels" what is the idea behind separating two related files in tow different folders Please answer my question
@williamliu8985
@williamliu8985 2 жыл бұрын
Thanks for sharing the MVVM experience, James! I have two questions. 1. How do you deside allocating the bussness logic into VM or service? (Roughly, I think the testable logic should go to service and do not put VM in unit tests.) 2. Have you ever exposing a service as get only property in VM (normally the service is injected as readonly filed ), then the View can consume this service directly through ViewModel? I tried it several times, but not sure if there is disadvatange by doing so. Thanks!
@wojciechsura
@wojciechsura 2 жыл бұрын
1. View detects, that user *performed an action*. Viewmodel decides *what should happen*. Service knows *how to do it*. For a long time I was against unit testing viewmodels, but it actually allows you to perform functional tests without live UI, which is faster than UI testing. 2. If you use properly dependency injection, I would simply inject service into view. There's nothing bad about it, but ask yourself twice if you are not trying to short-circuit view to service, because you will end up with business logic inside view and this is bad. View should have access only to those services, which helps it perform its role (presenting data and handling user interaction).
@williamliu8985
@williamliu8985 2 жыл бұрын
@@wojciechsura Thank you for replying me in detail, Sura! Here is my thoughts, 1. IMO, ViewModel provides the display source (property) and the action (command) for View, I would like to treat the viewmodel as a facade model, it doesn`t do the actual work, but dispatch the jobs to services. (if there is something related to UI element, we can achieve it through converter or behavior over property). Then I can mainly test the services and the View/ViewModel can get away from unit tests. 2. My intention was not to make all the service injected in property. Sometimes, we just make a property in ViewModel and forwarding this to a services property, just like the Monkeys property in MonkeysViewModel 7:05. How about puting this property into the MonkeyService, make the service as a get-only property instead of readonly filed? Then we can consume the Monkeys through MonkeyService.Monkeys in View? Which just make the ViewModel more clean and no need to test against ViewModel. The idea is making the ViewModel more slim and putting the logic into service as much as possible. For MVVMS, we just test the S part, cool?
@wojciechsura
@wojciechsura 2 жыл бұрын
@@williamliu8985 I gave a lot of thought to the pattern you are proposing (slim ViewModel). However I figured, that it would became something what I call "transparent transceivier", blindly passing data from view to service and the other way around. And this approach leads you to think (more or less consciously), *if it is actually needed at all*. Just look at your proposal of publishing service from viewmodel via property. In such case, why not simply provide the service to the view directly instead of trying to squeeze viewmodel to a minimum size? But then, effectively you will realize, that the service you tried to pass to the view *will actually become your viewmodel* and your viewmodel will become just a annoying layer in between view and service, which you try to squeeze, because in this form it actually (IMO) does next to nothing. Such transparent transceivier is a glue code and the glue code is something MVVM along with bindings tries to eliminate. That's why I decided to push making business decisions into the viewmodel: you may need to test it, true, but then in this approach there is no such "transparent" layer and therefore there is no need to publish services through a viewmodel's property. You may there think of a viewmodel actually as a service, which has very specific role to fulfill (handling business logic for a specific view).
@williamliu8985
@williamliu8985 2 жыл бұрын
@@wojciechsura To one of the questions: "why not simply provide the service to the view directly instead of trying to squeeze viewmodel to a minimum size?" Service is capable to provide a INPC property for View to comsume, but for the ICommand part, I think it would be better to utilize the RelayCommand(which relay the command to relevant service) in ViewModel for SRP consideration. Furthermore, providing services in View is hard to consume them or it`ll go though the UI event. If there are some specific property just related to the View which is not that related to the services, these property can still stay in ViewModel. I`m not a native Enlish speaker, but yes, I like the concept "glue" for ViewModel. Don`t put too much into it, keep it simple and slim.What I'm thinking right now is, View is the consumer, ViewModel is the glue, Service is the core. Thanks for discussing this! I would like to see the ideas from yours. Everyone may have different perceptions and understandings of MVVM, some of which are based on the problems encountered in real projects.
@williamliu8985
@williamliu8985 2 жыл бұрын
One more thing to clarify out, when I mentioned injecting as property, I was talking about the following code style, the injection was captured as property but not field, as View can consume the service`s property directly without wrapping it again in VM: public class MainViewModel { public IMonkeyService MonkeyService { get; } public MainViewModel(IMonkeyService monkeyService) { MonkeyService = monkeyService; } } but if there is no need to consume the property from the service, the service can also be captured as filed.
@TaughtSimply
@TaughtSimply 2 жыл бұрын
Hey! I was wondering if you would be able to do Xamarin WebSockets tutorial? Or direct me to it one?
@nyashamuzeza3696
@nyashamuzeza3696 Жыл бұрын
Thank you ❤🔥
@abdulwasey1151
@abdulwasey1151 Жыл бұрын
All good. But I think MonkeyService should implement IMonkeyService, And then we will be able to mock it in our integration tests by using moq. If there is any other way to mock concrete classes.. Please enlighten me with that method. Thanks!
@JamesMontemagno
@JamesMontemagno Жыл бұрын
Sure! Interfaces are great :)
@HOWYOUDOIN884
@HOWYOUDOIN884 3 ай бұрын
Is there code to download? Can't see all of it in video so it's impossible to see what you are talking about. Would be nice if your videos had more diagrams.
@JamesMontemagno
@JamesMontemagno 3 ай бұрын
Its the workshop code: github.com/dotnet-presentations/dotnet-maui-workshop
@LeutnantJoker
@LeutnantJoker Жыл бұрын
It's a good video but I'm confused that you consider this anything new. This service layer in parallel to the main M VM V stack has always existed. That's been a part of the MVVM architecture as long as I can remember. How is this anything new?
@jayveebelano9041
@jayveebelano9041 2 жыл бұрын
can I get a link of codes? thanks in advance!!
@kopilkaiser8991
@kopilkaiser8991 Жыл бұрын
💯
@FnOTradingLearner
@FnOTradingLearner Жыл бұрын
Why there is no sample template with MVVM or MVVMS or any pattern with two field of CRUD operation so that anybody can start with say simple crud or master detail crud and modify just model class and other entities and good to go !
@ferccino
@ferccino 2 жыл бұрын
MVVMZ Model View ViewModel Zervices
@CikaGrma
@CikaGrma 2 жыл бұрын
Have you used Prism?
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
I haven't used it in projects personally, but I have explored it.
@BrianLagunas
@BrianLagunas 2 жыл бұрын
As you may know, Prism has been recommending this since 2008. Although this isn't really MVVM specific, it is a good pattern to use in your app development regardless if you are using MVVM or not.
@CaraParker-j7n
@CaraParker-j7n 3 ай бұрын
Anderson Joseph Walker Shirley Young Jason
@zandeecalma4801
@zandeecalma4801 2 жыл бұрын
Oce
@JamesMontemagno
@JamesMontemagno 2 жыл бұрын
Yup, that is who I worked for :)
@sandromagalli8587
@sandromagalli8587 Жыл бұрын
The same thing would be nice in Blazor, but there is not community toolkit for that, why people like to have viewmodels in xamarin/maui used in this way and not in Blazor? You end up writing the logic in the component so you can't really swap framework. ReactiveUI does it anyway so it can work. At the end of the day you can just implement INotifyPropertyChanged and call StateHasChanged on it but it seems like the Blazor team don't really want to support such pattern or am i wrong?
@BenYehudaOfficial
@BenYehudaOfficial 2 ай бұрын
Hey bro. I like your videos and I need some help with my project do you have a discord i can contact you directly?
@littelbro14
@littelbro14 2 жыл бұрын
.NET Jesus
What is the MVVM pattern, What benefits does MVVM have?
22:38
James Montemagno
Рет қаралды 101 М.
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 9 МЛН
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 13 МЛН
The Logging Everyone Should Be Using in .NET
15:34
Nick Chapsas
Рет қаралды 85 М.
What's new in .NET 9 and C# 13
19:21
Filip Ekberg
Рет қаралды 18 М.
.NET MAUI's Navigation for Beginners - Push, Pop, & Pass Objects
21:36
James Montemagno
Рет қаралды 69 М.
.NET and C# are in trouble. Here is what I'd do.
10:57
Ed Andersen
Рет қаралды 107 М.
Everything You NEED to Know About Client Architecture Patterns
5:51
XAML Data Binding and MVVM Basics (.NET MAUI, WPF, UWP, Xamarin.Forms)
19:15
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 263 М.
Forget Controllers and Minimal APIs in .NET!
14:07
Nick Chapsas
Рет қаралды 76 М.