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
@@ -0,0 +1,26 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Hyperbar.Desktop
{
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddSomething<TCommandBuilder>(this IServiceCollection services)
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;
}
}
}
@@ -2,6 +2,7 @@
namespace Hyperbar.Desktop
{
public interface ITemplateGeneratorFactory
{
DataTemplate Create();
@@ -9,10 +9,10 @@ public class TemplateGeneratorFactory :
public DataTemplate Create()
{
string xamlString = @"
<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:desktop='using:Hyperbar.Desktop'>
<desktop:TemplateGeneratorControl />
</DataTemplate>";
<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:desktop='using:Hyperbar.Desktop'>
<desktop:TemplateGeneratorControl />
</DataTemplate>";
return (DataTemplate)XamlReader.Load(xamlString);
}