dotnet / dotnet/maui

Add support for hosted services in .NET MAUI apps

Open
#2,244 27 comments 32 reactions 0 assignees View on GitHub
area-core-hosting Task
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 14h
Merged PRs (30d)
296

Description

Look into using [hosted services](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.ihostedservice?view=dotnet-plat-ext-5.0). This would replace the icky `IMauiInitializeService` that was added in https://github.com/dotnet/maui/pull/2137, and also to enable users to use hosted services. MAUI will automatically call StartAsync/StopAsync at the appropriate time. Sadly, this pattern is async-only, whereas in MAUI the call sites are always (or at least almost always) sync. But given that this is app startup/shutdown, doing async-over-sync might be OK (we would block).

This is a follow-up to PR https://github.com/dotnet/maui/pull/2137.

Other notes:
* Need to consider this when implementing: https://github.com/dotnet/aspnetcore/pull/36122

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the IMauiInitializeService introduced in PR #2137, then read IHostedService and the linked ASP.NET Core PR. Done means MAUI supports hosted services and invokes StartAsync and StopAsync at the appropriate application lifecycle points while addressing the async-over-sync startup and shutdown concern.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop-dev, mobile-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.