Book Image

The MVVM Pattern in .NET MAUI

By : Pieter Nijs
Book Image

The MVVM Pattern in .NET MAUI

By: Pieter Nijs

Overview of this book

In today's fast-paced world of modern software development, teams need to be efficient, productive, and capable of rapidly adapting to changes to deliver high-quality products, making it crucial for developers to write maintainable and easy-to-test code. The MVVM Pattern in .NET MAUI helps you to thoroughly explore the Model-View-View Model (MVVM) design pattern. The chapters show you how this pattern helps in structuring code to embrace the separation of concerns, allowing for loosely coupled user interface and application logic, which ultimately empowers you to write more robust, maintainable, and testable code. The book also highlights .NET MAUI's capabilities and features, and enables you to delve into the essential components within the framework that facilitate the application of the MVVM pattern. With the help of a sample application, this definitive guide takes a hands-on approach to walk you through both the essential and advanced usages of the MVVM pattern to ensure that you successfully apply the practical aspects of the pattern to your .NET MAUI projects. By the end of this book, you’ll have gained a comprehensive understanding of the MVVM design pattern and its relevance in the context of .NET MAUI, as well as developed the skills needed to successfully apply it in practice.
Table of Contents (20 chapters)
Free Chapter
1
Part 1: Key Concepts and Components
8
Part 2: Building a .NET MAUI App Using MVVM
13
Part 3: Mastering MVVM Development

What this book covers

Chapter 1, The MVVM Design Pattern, provides an overview of the core components of the MVVM pattern, showing their roles and interplay. It illustrates the value of separating UI from logic for better testability and maintenance. It addresses common MVVM misconceptions and offers a foundational grasp of MVVM, regardless of specific technology.

Chapter 2, What Is .NET MAUI?, gives an overview of the overarching landscape of .NET MAUI, its pivotal features and advantages, and its architecture. It provides insights into .NET MAUI’s origins from Xamarin and Xamarin Forms, and its evolutionary journey.

Chapter 3, Data Binding Building Blocks in .NET MAUI, shows how data binding in .NET MAUI, a cornerstone for MVVM, is an essential part of .NET MAUI. This chapter unpacks the key principles, elements, and techniques underpinning this essential feature.

Chapter 4, Data Binding in .NET MAUI, builds upon the previous chapter but delves deeper into its intricacies and nuances, offering a comprehensive exploration of all the aspects of data binding in .NET MAUI.

Chapter 5, Community Toolkits, zeros in on two influential community toolkits: the MVVM Toolkit and the .NET MAUI Community Toolkit. It shows how these community-driven initiatives can amplify the effectiveness of MVVM in your .NET MAUI applications.

Chapter 6, Working with Collections, provides an overview of how to effectively display datasets using MVVM in .NET MAUI. From binding data and adapting to its changes to crafting data templates, this chapter offers an MVVM-centric guide to presenting data and facilitating user interactions with it.

Chapter 7, Dependency Injection, Services, and Messaging, illuminates the methods of aligning a ViewModel with a view via service registration and dependency injection. It highlights the nuances of injecting services into a ViewModel and facilitating seamless communication between ViewModels using messaging, all while upholding separation of concerns and enhancing testability.

Chapter 8, Navigation in .NET MAUI, is all about MVVM-based navigation. This chapter provides an overview of what .NET MAUI Shell is and its implications for navigation. It shows how to construct a navigation service tailored for both .NET MAUI apps that leverage Shell and apps that don’t.

Chapter 9, Handling User Input and Validation, shows how to effectively handle user input, from validating data at the ViewModel level, standard and custom validation rules, to prompting the user for confirmations or cancellations in the presence of unsaved changes.

Chapter 10, Working with Remote Data, shows how to work with remote data, introduces repositories for maintaining separation of concerns, and utilizes dependency injection. It illustrates how to use Refit for streamlined API interactions, and how to handle asynchronous tasks and their UI implications.

Chapter 11, Creating MVVM-Friendly Controls, dives into the creation of custom controls that are tailored for MVVM, supporting data binding and interactivity through commands.

Chapter 12, Localization with MVVM, provides an overview of the techniques to localize hardcoded labels within the app, and how to effectively fetch language-specific data from APIs.

Chapter 13, Unit Testing, shows how easy and essential unit testing is. It guides you through setting up a unit test project, generating data, mocking dependencies, and testing MAUI code.

Chapter 14, Troubleshooting and Debugging Tips, highlights common hiccups and their solutions. It shows typical issues and pitfalls concerning data binding, dependency injection, and building custom controls and converters.