using Hyperbar.Desktop.Contextual; using Hyperbar.Desktop.Controls; using Hyperbar.Desktop.Primary; using Hyperbar.Lifecycles; using Hyperbar.Templates; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.UI.Xaml; using System; using System.Collections.Generic; namespace Hyperbar.Desktop; public partial class App : Application { public App() => InitializeComponent(); protected override async void OnLaunched(LaunchActivatedEventArgs args) { base.OnLaunched(args); IHost? host = Host.CreateDefaultBuilder() .UseContentRoot(AppContext.BaseDirectory) .ConfigureServices(services => { services.AddHostedService(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddDataTemplate(); services.AddCommandBuilder("Contexual.Commands"); services.AddCommandBuilder("Primary.Command"); services.AddTransient(provider => { static IEnumerable Resolve(IServiceProvider services) { foreach (ICommandContext commandContext in services.GetServices()) { if (commandContext.ServiceProvider.GetService() is ICommandViewModel commandViewModel) { yield return commandViewModel; } } } return Resolve(provider); }); }) .Build(); await host.RunAsync(); } }