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

Sdílet
Vložit
  • čas přidán 19. 06. 2024
  • 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
  • Věda a technologie

Komentáře • 120

  • @_SkyDancer
    @_SkyDancer Před 2 měsíci +1

    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.

  • @Polynuttery
    @Polynuttery Před rokem +23

    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.

    • @Dazza_Doo
      @Dazza_Doo Před rokem +1

      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.

  • @keigezellig
    @keigezellig Před 3 měsíci +1

    I am doing some MAUI development lately (and have previous experience with MVVM) and this is EXACTLY the architecture i am using! 😊

  • @johnallcock5582
    @johnallcock5582 Před rokem +1

    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.

  • @lucecarter
    @lucecarter Před rokem +5

    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 Před rokem +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!

  • @carterash2588
    @carterash2588 Před 3 měsíci +1

    James, these videos have really inspired me to learn C#, Xmal, .Net, Maui......and now MVVMS lol

  • @yosimadsu2189
    @yosimadsu2189 Před rokem +1

    Your MVVMS is actually the easiest way to approach app design. Thanks a lot 👍👍👍

  • @Armonica1967
    @Armonica1967 Před 7 měsíci

    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!!!
    👍👍👍👍😀😀

  • @krccmsitp2884
    @krccmsitp2884 Před rokem +2

    Makes total sense and it's as I always understood MVVM, thinking of the S(ervices) implicitly.

  • @AlSavant
    @AlSavant Před rokem +6

    "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.

  • @romanbohun9721
    @romanbohun9721 Před rokem +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!

  • @vincentotieno9197
    @vincentotieno9197 Před rokem +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).

  • @carlosdelvalle5417
    @carlosdelvalle5417 Před rokem +2

    I think it is pretty clear 😊. I’ll go refactor my current app right now!

  • @HijiHakimaru
    @HijiHakimaru Před rokem

    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!

  • @jutyarr
    @jutyarr Před rokem +1

    pretty nice as always James, for those who are new or confused, please watch "The Xamarin Show | Episode 13: MVVM Helpers" by james

  • @usmcmckee
    @usmcmckee Před rokem

    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.

  • @gerryan9710
    @gerryan9710 Před rokem +1

    I also used that pattern and it was really easy to maintain.

  • @johnb2572
    @johnb2572 Před rokem

    Nice, very well explained thanks

  • @Ryan-tg1mx
    @Ryan-tg1mx Před rokem +5

    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?

  • @DanSiegel
    @DanSiegel Před rokem +11

    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  Před rokem +12

      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 Před rokem

      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 Před rokem

      I agree. Watched the video to see what the 'S' was and realized it's just MVVM :/

  • @chrissmith9725
    @chrissmith9725 Před 10 měsíci +1

    Really helpful thankyou JM

  • @DTGxliljarhead
    @DTGxliljarhead Před rokem

    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!

  • @OneMassiveMan
    @OneMassiveMan Před rokem

    You’re the best James I watch all your videos

  • @zarokoshin4090
    @zarokoshin4090 Před rokem

    Great Video !! It would be cool if you make a video about Content Provider to share SQLite database across apps (locally)…

  • @spaprune
    @spaprune Před rokem

    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.

  • @logank.70
    @logank.70 Před rokem +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 Před rokem

      I came in the comments looking for this reply.

  • @TuxCommander
    @TuxCommander Před rokem +4

    Actually this is my approach since I develop WPF applications and it shakes me, when I see VMs with SQL or dbcontext inside.

  • @EnriqueThedy
    @EnriqueThedy Před rokem

    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!

  • @petermurton4328
    @petermurton4328 Před rokem +1

    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?

  • @nyashamuzeza3696
    @nyashamuzeza3696 Před rokem

    Thank you ❤🔥

  • @megaman2016
    @megaman2016 Před rokem

    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.

  • @TornTech1
    @TornTech1 Před rokem

    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?

  • @btigenie
    @btigenie Před rokem

    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  Před rokem +1

      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 Před rokem

      @@JamesMontemagnoUnless you have other layers that might need to access the DB, you put everything in the Service layer?

  • @laurolnunes
    @laurolnunes Před rokem

    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?

  • @MrSikesben
    @MrSikesben Před rokem +1

    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

  • @buddysnackit1758
    @buddysnackit1758 Před rokem

    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.

  • @Speede04
    @Speede04 Před rokem

    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.

  • @hastifallah73
    @hastifallah73 Před rokem

    Hi. It would be so great if you make a video about comparison between flatter and Maui

  • @elemiliio4582
    @elemiliio4582 Před rokem

    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 Před rokem

      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...

  • @neralem
    @neralem Před rokem

    You showcased the CommunityToolkit preview that offers mvvm with source generators. Can you tell us how to use this with dedicated models?

  • @Moosa_Says
    @Moosa_Says Před rokem +1

    Exact pattern that i use but i always apply an Interface on a service, for testability :)

  • @technics6215
    @technics6215 Před rokem +1

    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?

  • @cbradbaer
    @cbradbaer Před rokem

    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  Před rokem

      Yes! In Preview 4 they renamed a few attributes -> github.com/CommunityToolkit/dotnet/releases/tag/v8.0.0-preview4

  • @OldShoolGames
    @OldShoolGames Před rokem

    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 ?

  • @gabrielheming
    @gabrielheming Před rokem

    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)?

  • @mikp1280
    @mikp1280 Před rokem

    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  Před rokem

      Can checkout Q&A: docs.microsoft.com/en-us/answers/products/dotnet

  • @junior.santana
    @junior.santana Před rokem

    Hey James have you talked about exception handling yet? That could be a nice video

  • @olagisrarikis
    @olagisrarikis Před rokem

    One quick question: Does "Visual Studio for ARM 2022" have .NET Maui workload on the roadmap?

  • @antisnufff
    @antisnufff Před 3 měsíci

    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

  • @d3hlvi
    @d3hlvi Před rokem

    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  Před rokem

      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.

  • @marikselazemaj3428
    @marikselazemaj3428 Před rokem

    Totally agree

  • @dreamdancer8212
    @dreamdancer8212 Před rokem +1

    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  Před rokem

      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 Před rokem

      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.

  • @deltaphilip8611
    @deltaphilip8611 Před rokem

    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?

  • @maheshkumbhar4216
    @maheshkumbhar4216 Před rokem

    Hi @James,
    What is future of Xamarin UiTest with MAUI ????

  • @Dave_Tries
    @Dave_Tries Před rokem

    Hey!
    I was wondering if you would be able to do Xamarin WebSockets tutorial? Or direct me to it one?

  • @AdamsTaiwan
    @AdamsTaiwan Před rokem

    I don't get the purpose of the AddSingleton, AddTransient, do you have a video on just these?

  • @Jake-iw3tl
    @Jake-iw3tl Před rokem

    I still remember a time before you looked like hippie Tech Jesus 😄
    And how do you not have more subscribers? 😮

  • @c0ward
    @c0ward Před rokem

    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  Před rokem +1

      I personally have an ObservableRangeCollection I use when adding a bunch of items. It is in my mvvm helpers library

  • @williamliu8985
    @williamliu8985 Před rokem

    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 Před rokem

      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 Před rokem

      @@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 Před rokem

      @@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 Před rokem

      @@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 Před rokem

      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.

  • @jagadishwarballa
    @jagadishwarballa Před rokem

    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.

  • @blackbeans3112
    @blackbeans3112 Před rokem

    Can I apply it in web development?

  • @TaoriUTS
    @TaoriUTS Před rokem

    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.

  • @marcinbalcerzyk84
    @marcinbalcerzyk84 Před rokem

    Hi. Does MVVMS makes sense for languages like Python?

  • @abdalghanialbiek8999
    @abdalghanialbiek8999 Před rokem

    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

  • @abdulwasey1151
    @abdulwasey1151 Před rokem

    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!

  • @kopilkaiser8991
    @kopilkaiser8991 Před rokem

    💯

  • @NK-xw4uu
    @NK-xw4uu Před rokem

    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.

  • @RexTorres
    @RexTorres Před rokem +1

    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. 😅

  • @jayveebelano9041
    @jayveebelano9041 Před rokem

    can I get a link of codes? thanks in advance!!

  • @internetissue4548
    @internetissue4548 Před rokem

    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

  • @CikaGrma
    @CikaGrma Před rokem

    Have you used Prism?

    • @JamesMontemagno
      @JamesMontemagno  Před rokem

      I haven't used it in projects personally, but I have explored it.

    • @BrianLagunas
      @BrianLagunas Před rokem

      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.

  • @ferccino
    @ferccino Před rokem +1

    MVVMZ
    Model
    View
    ViewModel
    Zervices

  • @FnOTradingLearner
    @FnOTradingLearner Před rokem

    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 !

  • @BrianLagunas
    @BrianLagunas Před rokem +1

    You know I love you bro, but that's just plain MVVM 👍

    • @JamesMontemagno
      @JamesMontemagno  Před rokem +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 Před rokem

      @@JamesMontemagno definitely. Thanks for taking the time to share and helping point people in the right direction.

    • @williamliu8985
      @williamliu8985 Před rokem +1

      Hi Brian, I haven't seen your update video for a long time, how are you doing?

    • @BrianLagunas
      @BrianLagunas Před rokem

      @@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 Před rokem +1

      @@BrianLagunas Great! Your cool videos inspired me a lot in the WPF/MVVM, thanks a lot!!

  • @LeutnantJoker
    @LeutnantJoker Před rokem

    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?

  • @zandeecalma4801
    @zandeecalma4801 Před rokem

    Oce

  • @azgan123
    @azgan123 Před rokem +1

    Amazing hair! I can't believe you've been hiding it under a hat for so long.

  • @sandromagalli8587
    @sandromagalli8587 Před rokem

    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?

  • @littelbro14
    @littelbro14 Před rokem

    .NET Jesus