Added json configuration
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user