MAUI Hosting
MAUI apps often end up with a massive MauiProgram.cs where every plugin, service, and lifecycle hook is crammed together. Shiny MAUI Hosting lets you break that apart into modular IMauiModule classes — each responsible for its own service registration and post-build initialization. It also provides a static Host.Services accessor, an IAppSupport service for orientation/culture/time-zone change detection and device info, and an IAppStore service for cross-platform store version lookups and deep links.
| GitHub | |
| Downloads |
Features
Section titled “Features”- Modular
IMauiModuleinterface — combines service registration and post-build initialization in one class - Static
Host.Servicesfor accessing the service provider from anywhere IAppSupport— device info, orientation control, and live change notifications for orientation, culture, and time zoneIAppStore— cross-platform store version lookups, deep links, and review-page launches for Apple App Store, Google Play, and Microsoft Store- Opt-in registration: each capability ships as its own extension method (
AddAppSupport,AddAppStore) so apps only pay for what they use
-
Install the NuGet package:
Terminal window dotnet add package Shiny.Extensions.MauiHosting -
Create a module for each concern:
using Shiny;public class MyModule : IMauiModule{public void Add(MauiAppBuilder builder){builder.Services.AddSingleton<IMyService, MyService>();}public void Use(IPlatformApplication app){// Post-build initialization (do NOT block here)}} -
Wire everything up in
MauiProgram.cs:using Shiny;var builder = MauiApp.CreateBuilder();builder.UseMauiApp<App>().AddInfrastructureModules(new MyModule()) // your IMauiModule list.AddAppSupport() // IAppSupport.AddAppStore(opts => // IAppStore (omit if not needed){opts.AppleAppId = "1234567890";opts.WindowsProductId = "9NBLGGH4NNS1";});return builder.Build();
Creating Modules
Section titled “Creating Modules”Each module implements IMauiModule with two methods:
Add(MauiAppBuilder builder)— register services, configure the builder. This runs before the app is built.Use(IPlatformApplication app)— post-build initialization. The service provider is available viaHost.Services. Do NOT block here — this runs on the main thread during app startup.
public class AnalyticsModule : IMauiModule{ public void Add(MauiAppBuilder builder) { builder.Services.AddSingleton<IAnalytics, AppCenterAnalytics>(); }
public void Use(IPlatformApplication app) { var analytics = Host.Services.GetRequiredService<IAnalytics>(); analytics.TrackEvent("AppStarted"); }}Static Host Access
Section titled “Static Host Access”After the app is built and initialized, Host.Services provides access to the service provider from anywhere:
// Resolve a service from anywhere in your appvar service = Host.Services.GetRequiredService<IMyService>();App Support
Section titled “App Support”IAppSupport provides device info, browser/map helpers, programmatic orientation control, and live change notifications for orientation, culture, and time zone. See App Support for the full member list and platform notes.
App Store
Section titled “App Store”IAppStore looks up the latest published version from the relevant platform store and deep-links into the store or review page. See App Store for configuration options and per-platform behavior.
AI Coding Assistant
Section titled “AI Coding Assistant”Step 1 — Add the marketplace:
claude plugin marketplace add shinyorg/skills Step 2 — Install the plugin:
claude plugin install shiny-extensions@shiny Step 1 — Add the marketplace:
copilot plugin marketplace add https://github.com/shinyorg/skills Step 2 — Install the plugin:
copilot plugin install shiny-extensions@shiny