inject the widget assembly into the IoC as we are going to need it further in
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetExtensionHandler(IProxyServiceCollection<IWidgetBuilder> typedServices,
|
||||
IServiceProvider provider,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<Created<WidgetExtension>>
|
||||
{
|
||||
public async Task Handle(Created<WidgetExtension> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if(notification.Value is WidgetExtension widgetExtension)
|
||||
{
|
||||
IWidgetBuilder builder = widgetExtension.Widget.Create();
|
||||
|
||||
builder.ConfigureServices(args =>
|
||||
{
|
||||
args.AddSingleton(widgetExtension.Assembly);
|
||||
args.AddTransient(_ => provider.GetRequiredService<IProxyService<IMediator>>());
|
||||
args.AddRange(typedServices.Services);
|
||||
});
|
||||
|
||||
IWidgetHost host = builder.Build();
|
||||
await host.InitializeAsync();
|
||||
|
||||
await mediator.PublishAsync(new Created<IWidgetHost>(host),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user