Welcome to the Sands of MAUI—newsletter-style issues dedicated to bringing together latest .NET MAUI content relevant to developers.
A particle of sand—tiny and innocuous. But put a lot of sand particles together and we have something big—a force to reckon with. It is the smallest grains of sand that often add up to form massive beaches, dunes and deserts.
Most .NET developers are excited with .NET Multi-platform App UI (MAUI)—the evolution of modern .NET cross-platform developer experience. Going forward, developers should have much more confidence in the technology stack and tools as .NET MAUI empowers native cross-platform solutions on both mobile and desktop.
While it may take a long flight to reach the sands of MAUI island, developer excitement around .NET MAUI is quite palpable in all the shared content. Like the grains of sand, every piece of news/article/documentation/video/tutorial/livestream contributes towards developer knowledge in .NET MAUI and we grow a community/ecosystem willing to learn & help.
Sands of MAUI is a humble attempt to collect all the .NET MAUI awesomeness in one place. Here's what is noteworthy for the week of August 29, 2022:
Dependency Injection (DI) in modern .NET is elegantly done and has been around for a while—for ASP.NET, Blazor and more. However, the .NET generic host builder pattern is new in .NET MAUI, and as such, DI may be relatively new for .NET MAUI developers.
While DI concepts are well established, not all service registrations/lifetimes are the same—James Montemagno produced a video breaking down the differences in .NET Dependency Injection.
There are a few ways to handle injected service lifespan in .NET MAUI Dependency Injection—Singleton, Transient and Scoped, with the first two being most commonly used. Singleton provides a true single instance of whatever is registered, while Transient is the opposite—every request produces a fresh instance. Choosing which one to use depends on developer scenarios and application needs. Using a .NET MAUI app with a View and ViewModel combo as base, James took on explaining the differences in .NET Dependency Injection.
While Singleton and Transient behave as expected, there are some nuanced conditions that might be trip-ups—kudos to James for producing a video that is on-point and explains the differences clearly.
Need to play any kind of audio from your .NET MAUI app? Gerald Versluis and Shaun Lawrence have you covered with the Plugin.Maui.Audio package, a one-stop shop to play just about anything. Shaun also wrote up a post on how to play audio from inside .NET MAUI apps, complete with an adorable .NET Bot playing a Ukulele tune on a guitar—because why not?
To get started, developers have to pull in the Plugin in their .NET MAUI apps and register the AudioManager through Dependency Injection. With an instance of IAudioPlayer, the player can play audio files that are either embedded as a file in the app or if pointed to an audio stream. Features like Play/Pause/Stop/Loop are built in, but the IAudioPlayer implements IDisposable—so developers should Dispose the player when done using it.
Cheers Shaun and Gerald for this straightforward but well-implemented audio player for all .NET MAUI apps—let there be music.
.NET MAUI apps do not live in a silo—just like any other modern app, they would need to integrate with other systems, talk to APIs or communicate with web services. A common scenario for those invested in Microsoft technology stack is to have client and server both in .NET—have .NET MAUI as the cross-platform client app and a .NET API backing it up on the server. Wouldn't it be nice if there was an end-to-end tutorial for the whole picture?
Les Jackson has done just that with an epic video building both a .NET MAUI app and a backing .NET 6 API—both in steps.
The long format video starts out with Les explaining the .NET MAUI basics, an app demo and walkthrough of corresponding architectures. Les then proceeds to build the .NET API backend with Entity Framework and full Create/Read/Update/Delete (CRUD) operation support. Next up comes the .NET MAUI app built up over small steps—the UI, code-behind and integrating with the data service.
With excellent teaching skills, Les showcases how developers can achieve end-to-end goal with .NET and .NET MAUI—cheers to learning.
With .NET MAUI as a platform out for a few months now and developer tooling coming out of Preview, arguably a lot more developers are getting into the mix. And developer productivity needs a rich ecosystem.
Developers need UI ammunition to kick-start their cross-platform journey or to modernize applications. Telerik UI for .NET MAUI is the most comprehensive UI component library featuring rich performant UI that runs seamlessly on mobile/desktop. A recent write-up shed light on the state of .NET MAUI and Telerik UI tooling.
The latest release of Telerik UI for .NET MAUI marked as 2.3.0, goes with the latest .NET MAUI release 6.0.424. Tooling is integrated with Visual Studio 2022—17.3 release version on Windows and 17.4 preview on MacOS. An integrated Toolbox keeps all Telerik UI at hand and hooks are in place to speed up developer inner loop in the usual ways—Hot Reload and Live Visual Tree.
With open source real-world demo apps and solid docs, Telerik UI for .NET MAUI aims to make .NET MAUI developers a little more productive and be able drop rich performant UI in cross-platform mobile/desktop apps.
Sonos Inc. is an American manufacturer of audio products, with lineup of powered speakers, amplifiers and peripherals—like portable speakers, soundbars, sub-woofers and integrated components. Sonos speakers can be controlled with the Sonos app, but let's face it—you are a developer and you would rather build something custom through integrations with the Sonos API.
Turns out, .NET MAUI can help and Andreas Nesheim wrote up an article on how to control Sonos speakers through API integration within a .NET MAUI app.
Developers can start with a fresh .NET MAUI app and pull in the ByteDev.Sonos NuGet package—this plugin allows communications with Sonos speakers with commands like play/pause, next/previous track, volume up/down and adding songs to queue. Before any integrations, developers need to find the IP of the Sonos speaker they're trying to reach—the Sonos app can help.
Once configured, a SonosController class can expose all API in a a fluent asynchronous way—play, pause, next and more. Andreas shows off how to pull this off from a simple .NET MAUI app—now you have one more reason to go grab a Sonos speaker.
That's it for now.
We'll see you next week with more awesome content relevant to .NET MAUI.
Cheers, developers!
Sam Basu is a technologist, author, speaker, Microsoft MVP, gadget-lover and Progress Developer Advocate for Telerik products. With a long developer background, he now spends much of his time advocating modern web/mobile/cloud development platforms on Microsoft/Telerik technology stacks. His spare times call for travel, fast cars, cricket and culinary adventures with the family. You can find him on the internet.