Added json configuration

This commit is contained in:
TheXamlGuy
2024-01-05 17:34:09 +00:00
parent d94add17f9
commit e180c966ff
33 changed files with 527 additions and 40 deletions
@@ -0,0 +1,22 @@
using Hyperbar.Desktop.Controls;
using Hyperbar.Lifecycles;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
namespace Hyperbar.Desktop;
public class AppInitializer([FromKeyedServices(nameof(CommandView))] CommandView view,
[FromKeyedServices(nameof(CommandView))] CommandViewModel viewModel,
DesktopFlyout desktopFlyout) :
IInitializer
{
public Task InitializeAsync()
{
view.DataContext = viewModel;
desktopFlyout.Placement = DesktopFlyoutPlacement.Top;
desktopFlyout.Content = view;
return Task.CompletedTask;
}
}
@@ -0,0 +1,29 @@
using Hyperbar.Lifecycles;
using Hyperbar.Templates;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Hyperbar.Desktop
{
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddCommandBuilder<TCommandBuilder>(this IServiceCollection services,
string key)
where TCommandBuilder :
ICommandBuilder, new()
{
TCommandBuilder builder = new();
IHost? host = new HostBuilder()
.ConfigureServices(services =>
{
services.AddTransient<ITemplateFactory, TemplateFactory>();
services.AddTransient<ITemplateGeneratorFactory, TemplateGeneratorFactory>();
builder.Create(services);
}).Build();
services.AddTransient<ICommandContext>(provider => new CommandContext(host.Services));
return services;
}
}
}