liveBook · Manning

Reuse

As explained in .NET MAUI in Action

Code reuse is the practice of using existing software logic or source code across multiple applications, components, or target platforms.

Code reuse means placing logic where multiple pages, applications, or platforms can use it instead of implementing the same behavior repeatedly. Moving business logic from page code-behind into services reduces UI coupling and makes the logic available wherever it is needed. section 8.1

Apply reuse progressively:

  • Define the required functionality and describe it with interfaces before implementing services. section 8.1
  • Share DTOs and client packages between projects so structural changes are visible across the solution. section 8.4.2
  • Package reusable business logic, UI, and UX modules as NuGet packages for use across enterprise solutions. section 8.4.3

MauiStockTake

A product-search and inventory-counter app can put its functionality in services rather than page code-behind. The same logic can then support multiple pages, while shared client code can extend to cloud, mobile, desktop, web, and future enterprise applications. section 8.1 section 8.4.2

Figure 8.6 MauiStockTake is a full-stack solution written in C#. Therefore, there is no need to duplicate code as it can be shared across the stack. Code shared across the stack in this way is referred to as cross-cutting concerns.

Use the full-stack diagram to see how a C# solution shares code across cloud, mobile, desktop, and web layers without duplicating cross-cutting concerns. section 8.4.2

Figure 8.7 The MauiStockTake app becomes part of an ecosystem if Mildred introduces a customer portal as well, which may require (among other things) an indication of the availability of products. The customer portal would likely have its own API, which could query the MauiStockTake API for this information. The customer portal could be built in Blazor, which would allow its controls to be abstracted back to a Razor class library. The class library could be used by .NET MAUI Blazor to provide the customer portal as an app, too. The controls in the MauiStockTake app could be abstracted back to a .NET MAUI class library to be shared with future apps too, which would maintain the visual consistency of Mildred’s brand.

Use the ecosystem diagram to trace shared business logic and UI across applications, APIs, Blazor, .NET MAUI, and reusable class libraries. section 8.4.3

How .NET MAUI in Action covers it

How deep it goes
Explains service extraction, interfaces, shared projects, and package distribution, but stops short of enterprise-scale implementation details.
Examples
Uses product search, inventory counting, shared DTOs, MauiStockTake, Blazor applications, and enterprise authentication as examples.
What you can do after
Build reusable .NET application logic by extracting services, sharing projects, and packaging common modules.
How it connects
Connects services, interfaces, business logic, DTOs, UI, UX, Blazor, Razor class libraries, and NuGet packages.

Also explained in

Compare how 6 books explain reuse →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.