restructure project for part 2
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user