Created
April 15, 2026 05:45
-
-
Save aetos382/1f1322a0ff064ac4b1b4802819635fba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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