get HB widgets showing up again
This commit is contained in:
@@ -155,7 +155,9 @@ public static class IServiceCollectionExtensions
|
||||
services.AddHandler<WidgetEnumerationHandler>();
|
||||
services.AddHandler<WidgetAssemblyHandler>();
|
||||
services.AddHandler<WidgetHandler>();
|
||||
services.AddHandler<WidgetHostHander>();
|
||||
services.AddHandler<WidgetHostHandler>();
|
||||
|
||||
services.AddTransient<IFactory<IWidgetHost, WidgetContainerViewModel?>, WidgetContainerFactory>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
[NotificationHandler(nameof(WidgetBarViewModel))]
|
||||
public partial class WidgetBarViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IEnumerable<WidgetContainerViewModel> items) :
|
||||
ObservableCollectionViewModel<WidgetContainerViewModel>(serviceFactory, mediator, disposer, items),
|
||||
IDisposer disposer) :
|
||||
ObservableCollectionViewModel<WidgetContainerViewModel>(serviceFactory, mediator, disposer),
|
||||
ITemplatedViewModel
|
||||
{
|
||||
public ITemplateFactory TemplateFactory => templateFactory;
|
||||
|
||||
@@ -7,15 +7,10 @@ public partial class WidgetContainerViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IEnumerable<IWidgetViewModel> items,
|
||||
Guid id,
|
||||
bool alternate) :
|
||||
ObservableCollectionViewModel<IWidgetViewModel>(serviceFactory, mediator, disposer, items),
|
||||
Guid id) :
|
||||
ObservableCollectionViewModel<IWidgetViewModel>(serviceFactory, mediator, disposer),
|
||||
ITemplatedViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool alternate = alternate;
|
||||
|
||||
[ObservableProperty]
|
||||
private Guid id = id;
|
||||
|
||||
|
||||
@@ -3,5 +3,7 @@
|
||||
public interface IWidgetHost :
|
||||
IInitializer
|
||||
{
|
||||
WidgetConfiguration Configuration { get; }
|
||||
|
||||
IServiceProvider Services { get; }
|
||||
}
|
||||
|
||||
@@ -50,15 +50,6 @@ public class WidgetBuilder<TConfiguration>(TConfiguration configuration) :
|
||||
public IWidgetHost Build()
|
||||
{
|
||||
IHost host = hostBuilder.Build();
|
||||
|
||||
//if (host.Services.GetRequiredService<IConfigurationInitializer<TConfiguration>>()
|
||||
// is IConfigurationInitializer<TConfiguration> configurationInitializer)
|
||||
//{
|
||||
// configurationInitializer.InitializeAsync()
|
||||
// .GetAwaiter()
|
||||
// .GetResult();
|
||||
//}
|
||||
|
||||
return (IWidgetHost)ActivatorUtilities.CreateInstance(host.Services,
|
||||
typeof(WidgetHost), host);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
namespace Hyperbar;
|
||||
|
||||
public class WidgetContainerFactory(IServiceFactory factory) :
|
||||
IFactory<IWidgetHost, WidgetContainerViewModel?>
|
||||
{
|
||||
public WidgetContainerViewModel? Create(IWidgetHost value)
|
||||
{
|
||||
if (value.Services.GetServices<IWidgetViewModel>() is
|
||||
IEnumerable<IWidgetViewModel> viewModels)
|
||||
{
|
||||
return factory.Create<WidgetContainerViewModel>(value.Configuration.Id);
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
@@ -27,6 +28,8 @@ public class WidgetHost :
|
||||
mediator.Subscribe(this);
|
||||
}
|
||||
|
||||
public WidgetConfiguration Configuration => host.Services.GetRequiredService<WidgetConfiguration>();
|
||||
|
||||
public IServiceProvider Services => host.Services;
|
||||
|
||||
public async Task Handle(Changed<WidgetAvailability> notification,
|
||||
@@ -45,15 +48,14 @@ public class WidgetHost :
|
||||
|
||||
private async Task StartAsync()
|
||||
{
|
||||
if (proxyMediator.Proxy is IMediator mediator)
|
||||
{
|
||||
await mediator.PublishAsync(new Started<IWidgetHost>(this));
|
||||
}
|
||||
|
||||
foreach (IInitializer initializer in initializers)
|
||||
{
|
||||
await initializer.InitializeAsync();
|
||||
}
|
||||
|
||||
|
||||
//if (proxyMediator.Proxy is IMediator mediator)
|
||||
//{
|
||||
// await mediator.PublishAsync(new Started<IWidgetHost>(this));
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public class WidgetHostHander :
|
||||
INotificationHandler<Started<IWidgetHost>>,
|
||||
INotificationHandler<Stopped<IWidgetHost>>
|
||||
{
|
||||
public Task Handle(Started<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// throw new NotImplementedException();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(Stopped<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public class WidgetHostHandler(IMediator mediator,
|
||||
IFactory<IWidgetHost, WidgetContainerViewModel?> factory) :
|
||||
INotificationHandler<Started<IWidgetHost>>,
|
||||
INotificationHandler<Stopped<IWidgetHost>>
|
||||
{
|
||||
public async Task Handle(Started<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is IWidgetHost host)
|
||||
{
|
||||
if (factory.Create(host) is WidgetContainerViewModel containerViewModel)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<WidgetContainerViewModel>(containerViewModel), nameof(WidgetBarViewModel),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task Handle(Stopped<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user