break widget related stuff into its own project as the main HB project was just becoming too bloated
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetHandler(IProxyServiceCollection<IWidgetBuilder> typedServices,
|
||||
IServiceProvider provider,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<Created<IWidget>>
|
||||
{
|
||||
public async Task Handle(Created<IWidget> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if(notification.Value is IWidget widget)
|
||||
{
|
||||
IWidgetBuilder builder = widget.Create();
|
||||
|
||||
builder.ConfigureServices(args =>
|
||||
{
|
||||
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