TemplateStudio
TemplateStudio copied to clipboard
IHostApplicationLifetime never invoke shutdown callbacks in WinUI templates
trafficstars
Describe the bug
Callbacks on the IHostApplicationLifetime interface is never invoked when the App is closed.
To Reproduce
- Create a service that uses IHostApplicationLifetime
public class DummyService
{
public DummyService(IHostApplicationLifetime hostApplicationLifetime)
{
hostApplicationLifetime.ApplicationStopping.Register(() =>
{
// This code is never called
});
}
}
- Configure service in app.xaml.cs
.ConfigureServices((context, services) =>
{
services.AddSingleton<DummyService>();
}
- Run the App and close it
- Result: The registered callback is never called and any background services added with
services.AddHostedService<MyHostedService>();is never started.
Additional context
No response
Applies to the following platforms:
- [X] WinUI
- [ ] WPF
- [ ] UWP
About your setup
- Visual Studio Version: 17.2.5
- Template Studio Wizard Version: 5.1
- Windows Build: 19044
I believe these events are only raised if you use Start/Stop/Run on the Host to control the application lifecycle, which the templates do not.