get plugin system working

This commit is contained in:
TheXamlGuy
2024-01-04 20:53:49 +00:00
parent da8af59391
commit d45076f2a9
24 changed files with 219 additions and 55 deletions
+30 -9
View File
@@ -1,8 +1,10 @@
using Hyperbar.Desktop.Controls;
using Hyperbar.Desktop.Contextual;
using Hyperbar.Desktop.Controls;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
namespace Hyperbar.Desktop;
@@ -17,18 +19,37 @@ public partial class App :
IHost? host = Host.CreateDefaultBuilder()
.UseContentRoot(AppContext.BaseDirectory)
.ConfigureServices(args =>
.ConfigureServices(services =>
{
args.AddTransient<IInitializer, AppInitializer>();
args.AddTransient<DesktopFlyout>();
services.AddHostedService<AppService>();
args.AddTransient<ITemplateFactory, TemplateFactory>();
args.AddTransient<ITemplateGeneratorFactory, TemplateGeneratorFactory>();
services.AddTransient<IInitializer, AppInitializer>();
services.AddTransient<DesktopFlyout>();
args.AddDataTemplate<CommandViewModel, CommandView>("Commands");
args.AddDataTemplate<ContextualCommandViewModel, ContextualCommandView>();
services.AddTransient<ITemplateFactory, TemplateFactory>();
services.AddTransient<ITemplateGeneratorFactory, TemplateGeneratorFactory>();
args.AddHostedService<AppService>();
services.AddDataTemplate<CommandViewModel, CommandView>("Commands");
// Commands
services.AddSomething<ContextualCommandBuilder>();
services.AddTransient(provider =>
{
IEnumerable<ICommandViewModel> Resolve(IServiceProvider services)
{
foreach (ICommandContext commandContext in services.GetServices<ICommandContext>())
{
if (commandContext.ServiceProvider.GetService<ICommandViewModel>() is
ICommandViewModel commandViewModel)
{
yield return commandViewModel;
}
}
}
return Resolve(provider);
});
})
.Build();