moerfixes
This commit is contained in:
@@ -7,7 +7,7 @@ public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddWidget(this IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IInitialization, WidgetExtensionInitializer>();
|
||||
services.AddTransient<IInitializer, WidgetExtensionInitializer>();
|
||||
services.AddTransient<IFactory<Type, IWidget>, WidgetFactory>();
|
||||
|
||||
services.AddHandler<WidgetExtensionEnumerator>();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetExtensionInitializer(IMediator mediator) :
|
||||
IInitialization
|
||||
IInitializer
|
||||
{
|
||||
public async Task InitializeAsync() =>
|
||||
await mediator.PublishAsync<Enumerate<WidgetExtension>>();
|
||||
|
||||
@@ -9,16 +9,17 @@ public sealed class WidgetHost :
|
||||
private readonly IServiceProvider services;
|
||||
private readonly IMediator mediator;
|
||||
private readonly IProxyService<IMediator> proxyMediator;
|
||||
private readonly IEnumerable<IHostedService> hostedServices;
|
||||
|
||||
public WidgetHost(IServiceProvider services,
|
||||
IMediator mediator,
|
||||
IProxyService<IMediator> proxyMediator)
|
||||
IProxyService<IMediator> proxyMediator,
|
||||
IEnumerable<IHostedService> hostedServices)
|
||||
{
|
||||
this.services = services;
|
||||
this.mediator = mediator;
|
||||
this.proxyMediator = proxyMediator;
|
||||
|
||||
mediator.Subscribe(this);
|
||||
this.hostedServices = hostedServices;
|
||||
}
|
||||
|
||||
public WidgetConfiguration Configuration =>
|
||||
@@ -33,6 +34,11 @@ public sealed class WidgetHost :
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
foreach (IHostedService service in hostedServices)
|
||||
{
|
||||
await service.StartAsync(cancellationToken);
|
||||
}
|
||||
|
||||
if (proxyMediator.Proxy is IMediator mediator)
|
||||
{
|
||||
await mediator.PublishAsync(new Started<IWidgetHost>(this),
|
||||
@@ -43,8 +49,11 @@ public sealed class WidgetHost :
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken = default)
|
||||
public async Task StopAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
foreach(IHostedService service in hostedServices)
|
||||
{
|
||||
await service.StopAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,10 @@ public class WidgetHostHandler :
|
||||
{
|
||||
if (notification.Value is IWidgetHost host)
|
||||
{
|
||||
if (host.Services.GetServices<IInitialization>() is
|
||||
IEnumerable<IInitialization> initializations)
|
||||
if (host.Services.GetServices<IInitializer>() is
|
||||
IEnumerable<IInitializer> initializations)
|
||||
{
|
||||
foreach (IInitialization initialization in initializations)
|
||||
foreach (IInitializer initialization in initializations)
|
||||
{
|
||||
await initialization.InitializeAsync();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetMonitor :
|
||||
IInitialization
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
|
||||
@@ -5,16 +5,16 @@ namespace Hyperbar.Widget;
|
||||
public class WidgetService :
|
||||
IHostedService
|
||||
{
|
||||
private readonly IEnumerable<IInitialization> initializers;
|
||||
private readonly IEnumerable<IInitializer> initializers;
|
||||
|
||||
public WidgetService(IEnumerable<IInitialization> initializers)
|
||||
public WidgetService(IEnumerable<IInitializer> initializers)
|
||||
{
|
||||
this.initializers = initializers;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (IInitialization initializer in initializers)
|
||||
foreach (IInitializer initializer in initializers)
|
||||
{
|
||||
await initializer.InitializeAsync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user