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,23 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetAssemblyHandler(IMediator mediator,
|
||||
IFactory<Type, IWidget> factory) :
|
||||
INotificationHandler<Created<Assembly>>
|
||||
{
|
||||
public Task Handle(Created<Assembly> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value?.GetTypes().FirstOrDefault(x => typeof(IWidget).IsAssignableFrom(x)) is Type widgetType)
|
||||
{
|
||||
if (factory.Create(widgetType) is IWidget widget)
|
||||
{
|
||||
mediator.PublishAsync(new Created<IWidget>(widget),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user