more settings work
This commit is contained in:
@@ -10,6 +10,8 @@ public static class IServiceCollectionExtensions
|
||||
services.AddTransient<IInitializer, WidgetExtensionInitializer>();
|
||||
services.AddTransient<IFactory<Type, IWidget>, WidgetFactory>();
|
||||
|
||||
services.AddSingleton<IWidgetHostCollection, WidgetHostCollection>();
|
||||
|
||||
services.AddHandler<WidgetExtensionEnumerator>();
|
||||
services.AddHandler<WidgetExtensionHandler>();
|
||||
services.AddHandler<WidgetHostHandler>();
|
||||
@@ -33,7 +35,7 @@ public static class IServiceCollectionExtensions
|
||||
services.AddKeyedTransient(typeof(IWidgetViewModel), key, contentType);
|
||||
services.TryAddKeyedTransient(key, (provider, key) => provider.GetService<IWidgetView>()!);
|
||||
|
||||
services.AddTransient<IViewModelTemplate>(provider => new ViewModelTemplate { ViewModelType = contentType, TemplateType = templateType, Key = key });
|
||||
services.AddTransient<IViewModelTemplate>(provider => new ViewModelTemplate { ViewModelType = contentType, ViewType = templateType, Key = key });
|
||||
|
||||
return services;
|
||||
}
|
||||
@@ -56,7 +58,7 @@ public static class IServiceCollectionExtensions
|
||||
|
||||
services.AddTransient<IViewModelTemplate>(provider =>
|
||||
new ViewModelTemplate { ViewModelType = contentType,
|
||||
TemplateType = templateType, Key = key });
|
||||
ViewType = templateType, Key = key });
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidgetHostCollection :
|
||||
IEnumerable<IWidgetHost>
|
||||
{
|
||||
void Add(IWidgetHost widgetHost);
|
||||
}
|
||||
@@ -26,17 +26,17 @@ public class WidgetBuilder :
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
services.AddSingleton<IWidgetHost, WidgetHost>();
|
||||
|
||||
services.AddScoped<IServiceFactory>(provider =>
|
||||
new ServiceFactory((type, parameters) =>
|
||||
ActivatorUtilities.CreateInstance(provider, type, parameters!)));
|
||||
|
||||
services.AddSingleton<SubscriptionCollection>();
|
||||
services.AddSingleton<ISubscriptionManager, SubscriptionManager>();
|
||||
services.AddScoped<SubscriptionCollection>();
|
||||
services.AddScoped<ISubscriptionManager, SubscriptionManager>();
|
||||
services.AddTransient<ISubscriber, Subscriber>();
|
||||
services.AddTransient<IPublisher, Publisher>();
|
||||
|
||||
services.AddScoped<IMediator, Mediator>();
|
||||
|
||||
services.AddScoped<IDisposer, Disposer>();
|
||||
|
||||
services.AddHandler<WidgetAvailabilityChangedHandler>();
|
||||
|
||||
@@ -7,16 +7,16 @@ public class WidgetExtensionHandler(IServiceProvider provider,
|
||||
IProxyServiceCollection<IWidgetBuilder> typedServices) :
|
||||
INotificationHandler<Create<WidgetExtension>>
|
||||
{
|
||||
public async Task Handle(Create<WidgetExtension> notification,
|
||||
public async Task Handle(Create<WidgetExtension> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if(notification.Value is WidgetExtension widgetExtension)
|
||||
if(args.Value is WidgetExtension widgetExtension)
|
||||
{
|
||||
IWidgetBuilder builder = widgetExtension.Widget.Create();
|
||||
builder.ConfigureServices(args =>
|
||||
{
|
||||
args.AddSingleton(widgetExtension.Assembly);
|
||||
args.AddTransient(_ => provider.GetRequiredService<IProxyService<IMediator>>());
|
||||
args.AddTransient(_ => provider.GetRequiredService<IProxyService<IPublisher>>());
|
||||
|
||||
args.AddRange(typedServices.Services);
|
||||
});
|
||||
|
||||
@@ -3,24 +3,13 @@ using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public sealed class WidgetHost :
|
||||
public sealed class WidgetHost(IServiceProvider services,
|
||||
IPublisher publisher,
|
||||
IProxyService<IPublisher> proxyPublisher,
|
||||
IEnumerable<IHostedService> hostedServices) :
|
||||
IWidgetHost
|
||||
{
|
||||
private readonly IServiceProvider services;
|
||||
private readonly IPublisher publisher;
|
||||
private readonly IProxyService<IMediator> proxyMediator;
|
||||
private readonly IEnumerable<IHostedService> hostedServices;
|
||||
|
||||
public WidgetHost(IServiceProvider services,
|
||||
IPublisher publisher,
|
||||
IProxyService<IMediator> proxyMediator,
|
||||
IEnumerable<IHostedService> hostedServices)
|
||||
{
|
||||
this.services = services;
|
||||
this.publisher = publisher;
|
||||
this.proxyMediator = proxyMediator;
|
||||
this.hostedServices = hostedServices;
|
||||
}
|
||||
private readonly IPublisher publisher = publisher;
|
||||
|
||||
public WidgetConfiguration Configuration =>
|
||||
Services.GetRequiredService<WidgetConfiguration>();
|
||||
@@ -39,7 +28,7 @@ public sealed class WidgetHost :
|
||||
await service.StartAsync(cancellationToken);
|
||||
}
|
||||
|
||||
if (proxyMediator.Proxy is IMediator mediator)
|
||||
if (proxyPublisher.Proxy is IPublisher publisher)
|
||||
{
|
||||
await publisher.PublishAsync(new Started<IWidgetHost>(this),
|
||||
cancellationToken);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetHostCollection :
|
||||
IWidgetHostCollection
|
||||
|
||||
{
|
||||
private readonly List<IWidgetHost> hosts = [];
|
||||
|
||||
public void Add(IWidgetHost host)
|
||||
{
|
||||
hosts.Add(host);
|
||||
}
|
||||
|
||||
public IEnumerator<IWidgetHost> GetEnumerator() =>
|
||||
hosts.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() =>
|
||||
hosts.GetEnumerator();
|
||||
}
|
||||
@@ -2,14 +2,16 @@
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetHostHandler :
|
||||
public class WidgetHostHandler(IWidgetHostCollection widgetHosts) :
|
||||
INotificationHandler<Create<IWidgetHost>>
|
||||
{
|
||||
public async Task Handle(Create<IWidgetHost> notification,
|
||||
public async Task Handle(Create<IWidgetHost> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is IWidgetHost host)
|
||||
if (args.Value is IWidgetHost host)
|
||||
{
|
||||
widgetHosts.Add(host);
|
||||
|
||||
if (host.Services.GetServices<IInitializer>() is
|
||||
IEnumerable<IInitializer> initializations)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user