Skip to content

Instantly share code, notes, and snippets.

@aetos382
Created April 15, 2026 05:45
Show Gist options
  • Select an option

  • Save aetos382/1f1322a0ff064ac4b1b4802819635fba to your computer and use it in GitHub Desktop.

Select an option

Save aetos382/1f1322a0ff064ac4b1b4802819635fba to your computer and use it in GitHub Desktop.
using System;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.UI.Xaml;
namespace Microsoft.Extensions.DependencyInjection;
internal static class WindowsAppServiceCollectionExtensions
{
extension(IServiceCollection services)
{
public IServiceCollection UseWinApp<TApplication>()
where TApplication : Application
{
ArgumentNullException.ThrowIfNull(services);
services.AddSingleton<Application, TApplication>();
services.Replace(ServiceDescriptor.Singleton<IHostLifetime, WindowsAppLifetime>());
return services;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment