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

2024 ж. 15 Мам.
29 318 Рет қаралды

If you are a C# and XAML developer you probably know about MVVM, but have you ever heard of MVVMS? It is the architecture pattern I have used in every application I have ever built since my first job at Canon years upon years ago! It is a simple but effective way of structing your code and going beyond MVVM to decouple logic into small services. This makes code more re-usable and testable. I break it all down!
Links
- .NET MAUI Workshop - github.com/dotnet-presentatio...
- Podcast App - github.com/microsoft/dotnet-p...
- Island Tracker - github.com/jamesmontemagno/ap...
- What is MVVM video - • What is the MVVM patte...
- .NET MAUI Workshop 4 Hour Video - • Learn .NET MAUI - Full...
Join this channel to get access to perks:
/ @jamesmontemagno
👕 Buy some swag! - jamesmontemagno.myspreadshop....
☕️ Buy me a coffee - www.buymeacoffee.com/jamesmon...
Follow:
👨‍💻 GitHub: github.com/jamesmontemagno
🦜 Twitter: / jamesmontemagno
📄 Website: www.montemagno.com
📰 Newsletter: newsletter.montemagno.com/
Chapters:
00:00 - Introduction
00:40 - Let's talk architecture!
02:30 - What is MVVMS?
03:30 - Monkey app walkthrough
05:30 - Models - how much logic should they have?
07:00 - ViewModels & Services - what should do what?
12:05 - Dependency Injection, Testing, & Wrap-up
Disclaimer: This channel, videos, and streams are created in my spare time and are a product of me... James Montemagno! They are NOT officially affiliated or endorsed by Microsoft (my employer) in any way. Opinions and views are my own.
What is on my hat? It is the CLE clothing logo because I am from Cleveland! Checkout their awesome CLE merch: cleclothingco.myshopify.com/
What is that art on my wall? It is an original piece from the French street artist Gregos of La Butte Montmartre: / bcez1onhiqx
My Setup:
📷 Canon M50 Mark II - amzn.to/3P8R7lp
💡 Nanoleaf Elements Lights - amzn.to/3umwJVW
🎙 Blue Spark Microphone - amzn.to/3qgtYkq
🎙 Blue Pop Filter - amzn.to/3jEWM3r
🤳 Rode Microphone Arm - amzn.to/2Z68AlE
🎧 Sony MDR7306 Headphones - amzn.to/372jxta
📲 Stream Deck - amzn.to/373Uk1n
📹 Elgato Cam Link - amzn.to/3a9eGbh
📷 GoPro Hero - amzn.to/374lm90
🖱 MX Master 2S Mouse - amzn.to/3d7J2gj
⌨️ Tecware Phantom Keyboard - amzn.to/3aUP4y9
#dotnet #dotnetmaui #architecture #csharp wpf mvvm uno platform .net maui data binding

Пікірлер
  • 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.

    @_SkyDancer@_SkyDancerАй бұрын
  • James: I would suggest that you use more diagrams to show what is grouped where and what communicates with what. Thus would make it so much clearer to some of us.

    @Polynuttery@Polynuttery Жыл бұрын
    • I agree, I think I will need to start my own Flow Charts, incorporating Toolkits, generators, and the new C# code. It's going to be a while before I can wrap my head around all of it.

      @Dazza_Doo@Dazza_Doo Жыл бұрын
  • 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.

    @johnallcock5582@johnallcock558211 ай бұрын
  • 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!

    @typhoonf6@typhoonf6 Жыл бұрын
  • James, these videos have really inspired me to learn C#, Xmal, .Net, Maui......and now MVVMS lol

    @carterash2588@carterash25882 ай бұрын
  • 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

    @lucecarter@lucecarter Жыл бұрын
  • Your MVVMS is actually the easiest way to approach app design. Thanks a lot 👍👍👍

    @yosimadsu2189@yosimadsu2189 Жыл бұрын
  • I am doing some MAUI development lately (and have previous experience with MVVM) and this is EXACTLY the architecture i am using! 😊

    @keigezellig@keigezellig2 ай бұрын
    • Great to hear!

      @JamesMontemagno@JamesMontemagno2 ай бұрын
  • Makes total sense and it's as I always understood MVVM, thinking of the S(ervices) implicitly.

    @krccmsitp2884@krccmsitp2884 Жыл бұрын
  • 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!!! 👍👍👍👍😀😀

    @Armonica1967@Armonica19676 ай бұрын
  • 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!

    @romanbohun9721@romanbohun9721 Жыл бұрын
    • What layers would you add Roman?

      @johnmcnulty1022@johnmcnulty1022 Жыл бұрын
  • 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!

    @HijiHakimaru@HijiHakimaru Жыл бұрын
  • Really helpful thankyou JM

    @chrissmith9725@chrissmith97259 ай бұрын
    • Glad it helped out

      @JamesMontemagno@JamesMontemagno9 ай бұрын
  • I also used that pattern and it was really easy to maintain.

    @gerryan9710@gerryan9710 Жыл бұрын
  • 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).

    @vincentotieno9197@vincentotieno9197 Жыл бұрын
    • yup. you can mock up your services much easier

      @namelastname4077@namelastname4077 Жыл бұрын
  • "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.

    @AlSavant@AlSavant Жыл бұрын
  • I think it is pretty clear 😊. I’ll go refactor my current app right now!

    @carlosdelvalle5417@carlosdelvalle5417 Жыл бұрын
  • pretty nice as always James, for those who are new or confused, please watch "The Xamarin Show | Episode 13: MVVM Helpers" by james

    @jutyarr@jutyarr Жыл бұрын
  • 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.

    @DanSiegel@DanSiegel Жыл бұрын
    • 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.

      @JamesMontemagno@JamesMontemagno Жыл бұрын
    • 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.

      @sebastianbusek2087@sebastianbusek2087 Жыл бұрын
    • I agree. Watched the video to see what the 'S' was and realized it's just MVVM :/

      @brandon-butler@brandon-butler Жыл бұрын
  • 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.

    @usmcmckee@usmcmckee Жыл бұрын
  • 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?

    @Ryan-tg1mx@Ryan-tg1mx Жыл бұрын
  • Nice, very well explained thanks

    @johnb2572@johnb2572 Жыл бұрын
  • You’re the best James I watch all your videos

    @OneMassiveMan@OneMassiveMan Жыл бұрын
    • @JamesMontemagno@JamesMontemagno Жыл бұрын
  • 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.

    @spaprune@spaprune Жыл бұрын
  • Actually this is my approach since I develop WPF applications and it shakes me, when I see VMs with SQL or dbcontext inside.

    @TuxCommander@TuxCommander Жыл бұрын
  • 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.

    @megaman2016@megaman2016 Жыл бұрын
  • 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!

    @DTGxliljarhead@DTGxliljarhead Жыл бұрын
  • Great Video !! It would be cool if you make a video about Content Provider to share SQLite database across apps (locally)…

    @zarokoshin4090@zarokoshin4090 Жыл бұрын
  • 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?

    @petermurton4328@petermurton4328 Жыл бұрын
  • Exact pattern that i use but i always apply an Interface on a service, for testability :)

    @Moosa_Says@Moosa_Says Жыл бұрын
  • 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.

    @logank.70@logank.70 Жыл бұрын
    • I came in the comments looking for this reply.

      @AlSavant@AlSavant Жыл бұрын
  • 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?

    @TornTech1@TornTech1 Жыл бұрын
  • 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!

    @EnriqueThedy@EnriqueThedy Жыл бұрын
  • 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?

    @btigenie@btigenie Жыл бұрын
    • I now consider the Repository and Service the same thing. I don't like to add that additional layer on. NO real reason IMHO.

      @JamesMontemagno@JamesMontemagno Жыл бұрын
    • @@JamesMontemagnoUnless you have other layers that might need to access the DB, you put everything in the Service layer?

      @btigenie@btigenie Жыл бұрын
  • Hi. It would be so great if you make a video about comparison between flatter and Maui

    @hastifallah73@hastifallah73 Жыл бұрын
  • Thank you ❤🔥

    @nyashamuzeza3696@nyashamuzeza3696 Жыл бұрын
  • 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

    @MrSikesben@MrSikesben Жыл бұрын
  • 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.

    @Speede04@Speede04 Жыл бұрын
  • 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 ?

    @OldShoolGames@OldShoolGames Жыл бұрын
  • 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?

    @technics6215@technics6215 Жыл бұрын
  • 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.

    @buddysnackit1758@buddysnackit1758 Жыл бұрын
  • 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

    @antisnufff@antisnufff2 ай бұрын
  • 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.

    @cbradbaer@cbradbaer Жыл бұрын
    • Yes! In Preview 4 they renamed a few attributes -> github.com/CommunityToolkit/dotnet/releases/tag/v8.0.0-preview4

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • You showcased the CommunityToolkit preview that offers mvvm with source generators. Can you tell us how to use this with dedicated models?

    @neralem@neralem Жыл бұрын
  • 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

    @elemiliio4582@elemiliio4582 Жыл бұрын
    • 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...

      @moranlg@moranlg Жыл бұрын
  • 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?

    @laurolnunes@laurolnunes Жыл бұрын
  • Hi @James, What is future of Xamarin UiTest with MAUI ????

    @maheshkumbhar4216@maheshkumbhar4216 Жыл бұрын
  • Totally agree

    @marikselazemaj3428@marikselazemaj3428 Жыл бұрын
  • Hey James have you talked about exception handling yet? That could be a nice video

    @junior.santana@junior.santana Жыл бұрын
    • Will add to list for sure!

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • 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.

    @d3hlvi@d3hlvi Жыл бұрын
    • 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.

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • 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)

    @mikp1280@mikp1280 Жыл бұрын
    • Can checkout Q&A: docs.microsoft.com/en-us/answers/products/dotnet

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • Hey! I was wondering if you would be able to do Xamarin WebSockets tutorial? Or direct me to it one?

    @Dave_Tries@Dave_Tries Жыл бұрын
  • 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

    @dreamdancer8212@dreamdancer8212 Жыл бұрын
    • 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 ;)

      @JamesMontemagno@JamesMontemagno Жыл бұрын
    • 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.

      @Adam-ce5mq@Adam-ce5mq Жыл бұрын
  • One quick question: Does "Visual Studio for ARM 2022" have .NET Maui workload on the roadmap?

    @olagisrarikis@olagisrarikis Жыл бұрын
  • 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)?

    @gabrielheming@gabrielheming Жыл бұрын
  • 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.

    @TaoriUTS@TaoriUTS Жыл бұрын
  • 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?

    @deltaphilip8611@deltaphilip8611 Жыл бұрын
  • 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!

    @williamliu8985@williamliu8985 Жыл бұрын
    • 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).

      @wojciechsura@wojciechsura Жыл бұрын
    • @@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?

      @williamliu8985@williamliu8985 Жыл бұрын
    • @@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).

      @wojciechsura@wojciechsura Жыл бұрын
    • @@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 Жыл бұрын
    • 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.

      @williamliu8985@williamliu8985 Жыл бұрын
  • I don't get the purpose of the AddSingleton, AddTransient, do you have a video on just these?

    @AdamsTaiwan@AdamsTaiwan Жыл бұрын
  • Can I apply it in web development?

    @blackbeans3112@blackbeans3112 Жыл бұрын
  • 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.

    @jagadishwarballa@jagadishwarballa Жыл бұрын
  • 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!

    @abdulwasey1151@abdulwasey1151 Жыл бұрын
    • Sure! Interfaces are great :)

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • I still remember a time before you looked like hippie Tech Jesus 😄 And how do you not have more subscribers? 😮

    @Jake-iw3tl@Jake-iw3tl Жыл бұрын
  • Hi. Does MVVMS makes sense for languages like Python?

    @marcinbalcerzyk84@marcinbalcerzyk84 Жыл бұрын
  • 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. 😅

    @RexTorres@RexTorres Жыл бұрын
  • 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.

    @NK-xw4uu@NK-xw4uu Жыл бұрын
  • 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?

    @c0ward@c0ward Жыл бұрын
    • I personally have an ObservableRangeCollection I use when adding a bunch of items. It is in my mvvm helpers library

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • 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

    @abdalghanialbiek8999@abdalghanialbiek8999 Жыл бұрын
    • Take a look at www.reactiveui.net/

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • 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

    @internetissue4548@internetissue4548 Жыл бұрын
  • can I get a link of codes? thanks in advance!!

    @jayveebelano9041@jayveebelano9041 Жыл бұрын
  • 💯

    @kopilkaiser8991@kopilkaiser8991 Жыл бұрын
  • Have you used Prism?

    @CikaGrma@CikaGrma Жыл бұрын
    • I haven't used it in projects personally, but I have explored it.

      @JamesMontemagno@JamesMontemagno Жыл бұрын
    • 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.

      @BrianLagunas@BrianLagunas Жыл бұрын
  • MVVMZ Model View ViewModel Zervices

    @ferccino@ferccino Жыл бұрын
  • 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 !

    @FnOTradingLearner@FnOTradingLearner Жыл бұрын
  • You know I love you bro, but that's just plain MVVM 👍

    @BrianLagunas@BrianLagunas Жыл бұрын
    • 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.

      @JamesMontemagno@JamesMontemagno Жыл бұрын
    • @@JamesMontemagno definitely. Thanks for taking the time to share and helping point people in the right direction.

      @BrianLagunas@BrianLagunas Жыл бұрын
    • Hi Brian, I haven't seen your update video for a long time, how are you doing?

      @williamliu8985@williamliu8985 Жыл бұрын
    • @@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!

      @BrianLagunas@BrianLagunas Жыл бұрын
    • @@BrianLagunas Great! Your cool videos inspired me a lot in the WPF/MVVM, thanks a lot!!

      @williamliu8985@williamliu8985 Жыл бұрын
  • 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?

    @LeutnantJoker@LeutnantJoker Жыл бұрын
  • Oce

    @zandeecalma4801@zandeecalma4801 Жыл бұрын
    • Yup, that is who I worked for :)

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • Amazing hair! I can't believe you've been hiding it under a hat for so long.

    @azgan123@azgan123 Жыл бұрын
    • It comes out on occasions ;)

      @JamesMontemagno@JamesMontemagno Жыл бұрын
  • 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?

    @sandromagalli8587@sandromagalli8587 Жыл бұрын
  • .NET Jesus

    @littelbro14@littelbro14 Жыл бұрын
KZhead