restructure project for part 2

This commit is contained in:
TheXamlGuy
2024-01-27 10:55:53 +00:00
parent a322893166
commit 48925b89ff
96 changed files with 383 additions and 351 deletions
+1
View File
@@ -3,6 +3,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>1ed4d3bf-c619-4e7e-bbb1-517754d864cd</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
@@ -0,0 +1,7 @@
namespace Hyperbar.Widget;
public interface IWidgetResourceInitialization :
IInitializer
{
}
+11 -3
View File
@@ -4,7 +4,8 @@ using System.Runtime.Loader;
namespace Hyperbar.Widget;
public class WidgetEnumerator(IHostEnvironment hostEnvironment,
public class WidgetEnumerator(IFactory<Type, IWidget> factory,
IHostEnvironment hostEnvironment,
IMediator mediator) :
INotificationHandler<Enumerate<IWidget>>
{
@@ -21,10 +22,17 @@ public class WidgetEnumerator(IHostEnvironment hostEnvironment,
.SelectMany(assemblyDirectory => Directory.GetFiles(assemblyDirectory, "*.dll"))
];
Parallel.ForEach(assemblyPaths, (string assemblyPath) =>
Parallel.ForEach(assemblyPaths, async (string assemblyPath) =>
{
Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);
mediator.PublishAsync(new Created<Assembly>(assembly));
if (assembly.GetTypes().FirstOrDefault(x => typeof(IWidget).IsAssignableFrom(x)) is Type widgetType)
{
if (factory.Create(widgetType) is IWidget widget)
{
await mediator.PublishAsync(new Created<IWidget>(widget),
cancellationToken);
}
}
});
}