Refactor
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
{
|
|
||||||
public record ConfigurationChanged<TConfiguration>(TConfiguration Configuration) where TConfiguration : class;
|
public record ConfigurationChanged<TConfiguration>(TConfiguration Configuration) where TConfiguration : class;
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
using Mediator;
|
using Mediator;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public class ConfigurationInitializer<TConfiguration> : IInitializable where TConfiguration : class, new()
|
||||||
{
|
{
|
||||||
public class ConfigurationInitializer<TConfiguration> : IInitializer where TConfiguration : class, new()
|
|
||||||
{
|
|
||||||
private readonly TConfiguration configuration;
|
private readonly TConfiguration configuration;
|
||||||
private readonly IMediator mediator;
|
private readonly IMediator mediator;
|
||||||
|
|
||||||
@@ -19,5 +19,4 @@ namespace Toolkit.Foundation
|
|||||||
await mediator.Send(configuration);
|
await mediator.Send(configuration);
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public class ConfigurationWriter<TConfiguration> : IConfigurationWriter<TConfiguration> where TConfiguration : class, new()
|
||||||
{
|
{
|
||||||
public class ConfigurationWriter<TConfiguration> : IConfigurationWriter<TConfiguration> where TConfiguration : class, new()
|
|
||||||
{
|
|
||||||
private readonly IConfiguration rootConfiguration;
|
private readonly IConfiguration rootConfiguration;
|
||||||
|
|
||||||
public ConfigurationWriter(IConfiguration rootConfiguration)
|
public ConfigurationWriter(IConfiguration rootConfiguration)
|
||||||
@@ -26,6 +26,4 @@ namespace Toolkit.Foundation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
{
|
|
||||||
public interface IConfigurationWriter<TConfiguration> where TConfiguration : class
|
|
||||||
{
|
|
||||||
void Write(string section, TConfiguration args);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public interface IConfigurationWriter<TConfiguration> where TConfiguration : class
|
||||||
|
{
|
||||||
|
void Write(string section, TConfiguration args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
{
|
|
||||||
public interface IWritableConfigurationProvider
|
|
||||||
{
|
|
||||||
void Write<TValue>(string section, TValue value) where TValue : class, new();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public interface IWritableConfigurationProvider
|
||||||
|
{
|
||||||
|
void Write<TValue>(string section, TValue value) where TValue : class, new();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public interface IWritableJsonConfigurationBuilder
|
||||||
{
|
{
|
||||||
public interface IWritableJsonConfigurationBuilder
|
|
||||||
{
|
|
||||||
Stream? DefaultFileStream { get; }
|
Stream? DefaultFileStream { get; }
|
||||||
|
|
||||||
IWritableJsonConfigurationBuilder AddDefaultConfiguration<TConfiguration>(string Key) where TConfiguration : class;
|
IWritableJsonConfigurationBuilder AddDefaultConfiguration<TConfiguration>(string Key) where TConfiguration : class;
|
||||||
@@ -9,6 +9,4 @@
|
|||||||
IWritableJsonConfigurationBuilder AddDefaultFileStream(Stream stream);
|
IWritableJsonConfigurationBuilder AddDefaultFileStream(Stream stream);
|
||||||
|
|
||||||
void Build(string path);
|
void Build(string path);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public interface IWritableJsonConfigurationDescriptor
|
||||||
{
|
{
|
||||||
public interface IWritableJsonConfigurationDescriptor
|
|
||||||
{
|
|
||||||
Type ConfigurationType { get; }
|
Type ConfigurationType { get; }
|
||||||
|
|
||||||
string Key { get; }
|
string Key { get; }
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ using System.Text.Json;
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public class WritableJsonConfigurationBuilder : IWritableJsonConfigurationBuilder
|
||||||
{
|
{
|
||||||
public class WritableJsonConfigurationBuilder : IWritableJsonConfigurationBuilder
|
|
||||||
{
|
|
||||||
private readonly List<IWritableJsonConfigurationDescriptor> descriptors = new();
|
private readonly List<IWritableJsonConfigurationDescriptor> descriptors = new();
|
||||||
|
|
||||||
public Stream? DefaultFileStream { get; private set; }
|
public Stream? DefaultFileStream { get; private set; }
|
||||||
@@ -105,6 +105,4 @@ namespace Toolkit.Foundation
|
|||||||
content = null;
|
content = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
{
|
|
||||||
public record WritableJsonConfigurationDescriptor(Type ConfigurationType, string Key) : IWritableJsonConfigurationDescriptor;
|
|
||||||
|
|
||||||
}
|
public record WritableJsonConfigurationDescriptor(Type ConfigurationType, string Key) : IWritableJsonConfigurationDescriptor;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public static class WritableJsonConfigurationExtensions
|
||||||
{
|
{
|
||||||
public static class WritableJsonConfigurationExtensions
|
|
||||||
{
|
|
||||||
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder,
|
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder,
|
||||||
string path)
|
string path)
|
||||||
{
|
{
|
||||||
@@ -71,6 +71,4 @@ namespace Toolkit.Foundation
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder, Action<WritableJsonConfigurationSource> configureSource) => builder.Add(configureSource);
|
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder, Action<WritableJsonConfigurationSource> configureSource) => builder.Add(configureSource);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ using Newtonsoft.Json;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
internal class WritableJsonConfigurationFile
|
||||||
{
|
{
|
||||||
internal class WritableJsonConfigurationFile
|
|
||||||
{
|
|
||||||
private readonly Dictionary<string, (JsonValueKind?, string?)> data = new(StringComparer.OrdinalIgnoreCase);
|
private readonly Dictionary<string, (JsonValueKind?, string?)> data = new(StringComparer.OrdinalIgnoreCase);
|
||||||
private readonly Stack<string> paths = new();
|
private readonly Stack<string> paths = new();
|
||||||
private JObject tokenCache = new();
|
private JObject tokenCache = new();
|
||||||
@@ -145,6 +145,4 @@ namespace Toolkit.Foundation
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ using Microsoft.Extensions.FileProviders;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public class WritableJsonConfigurationProvider : JsonConfigurationProvider, IWritableConfigurationProvider
|
||||||
{
|
{
|
||||||
public class WritableJsonConfigurationProvider : JsonConfigurationProvider, IWritableConfigurationProvider
|
|
||||||
{
|
|
||||||
public WritableJsonConfigurationProvider(JsonConfigurationSource source) : base(source)
|
public WritableJsonConfigurationProvider(JsonConfigurationSource source) : base(source)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -43,6 +43,4 @@ namespace Toolkit.Foundation
|
|||||||
document.WriteTo(writer);
|
document.WriteTo(writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public class WritableJsonConfigurationSource : JsonConfigurationSource
|
||||||
{
|
{
|
||||||
public class WritableJsonConfigurationSource : JsonConfigurationSource
|
|
||||||
{
|
|
||||||
public IWritableJsonConfigurationBuilder? Factory { get; set; }
|
public IWritableJsonConfigurationBuilder? Factory { get; set; }
|
||||||
|
|
||||||
public override IConfigurationProvider Build(IConfigurationBuilder builder)
|
public override IConfigurationProvider Build(IConfigurationBuilder builder)
|
||||||
@@ -24,5 +24,4 @@ namespace Toolkit.Foundation
|
|||||||
Factory?.Build(outputFile);
|
Factory?.Build(outputFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Mediator;
|
using Mediator;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
{
|
|
||||||
public abstract record Write<TConfiguration>(string Section, Action<TConfiguration> UpdateDelegate) : IRequest where TConfiguration : class;
|
public abstract record Write<TConfiguration>(string Section, Action<TConfiguration> UpdateDelegate) : IRequest where TConfiguration : class;
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
using Mediator;
|
using Mediator;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public class WriteHandler<TConfiguration> : IRequestHandler<Write<TConfiguration>> where TConfiguration : class
|
||||||
{
|
{
|
||||||
public class WriteHandler<TConfiguration> : IRequestHandler<Write<TConfiguration>> where TConfiguration : class
|
|
||||||
{
|
|
||||||
private readonly IMediator mediator;
|
private readonly IMediator mediator;
|
||||||
private readonly TConfiguration configuration;
|
private readonly TConfiguration configuration;
|
||||||
private readonly IConfigurationWriter<TConfiguration> writer;
|
private readonly IConfigurationWriter<TConfiguration> writer;
|
||||||
@@ -26,5 +26,4 @@ namespace Toolkit.Foundation
|
|||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public static class IHostBuilderExtensions
|
||||||
{
|
{
|
||||||
public static class IHostBuilderExtensions
|
|
||||||
{
|
|
||||||
public static IHostBuilder UseContentRoot(this IHostBuilder hostBuilder, string contentRoot, bool createDirectory)
|
public static IHostBuilder UseContentRoot(this IHostBuilder hostBuilder, string contentRoot, bool createDirectory)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(contentRoot) && createDirectory)
|
if (!Directory.Exists(contentRoot) && createDirectory)
|
||||||
@@ -13,5 +13,4 @@ namespace Toolkit.Foundation
|
|||||||
|
|
||||||
return hostBuilder.UseContentRoot(contentRoot);
|
return hostBuilder.UseContentRoot(contentRoot);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
using Mediator;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public static class IServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
public static class IServiceCollectionExtensions
|
|
||||||
{
|
|
||||||
public static IServiceCollection AddHandler<TRequestHandler>(this IServiceCollection serviceCollection)
|
public static IServiceCollection AddHandler<TRequestHandler>(this IServiceCollection serviceCollection)
|
||||||
{
|
{
|
||||||
serviceCollection.TryAdd(new ServiceDescriptor(typeof(TRequestHandler), typeof(TRequestHandler), ServiceLifetime.Transient));
|
serviceCollection.TryAdd(new ServiceDescriptor(typeof(TRequestHandler), typeof(TRequestHandler), ServiceLifetime.Transient));
|
||||||
@@ -14,9 +13,17 @@ namespace Toolkit.Foundation
|
|||||||
|
|
||||||
public static IServiceCollection AddFoundation(this IServiceCollection serviceCollection)
|
public static IServiceCollection AddFoundation(this IServiceCollection serviceCollection)
|
||||||
{
|
{
|
||||||
serviceCollection.AddSingleton<IServiceFactory>(provider => new ServiceFactory(provider.GetService, (instanceType, parameters) => ActivatorUtilities.CreateInstance(provider, instanceType, parameters!)));
|
serviceCollection.AddSingleton<IServiceFactory>(provider => new ServiceFactory(provider.GetService, (instanceType, parameters) => ActivatorUtilities.CreateInstance(provider, instanceType, parameters!)))
|
||||||
|
.AddSingleton<IInitialization, Initialization>(provider => new Initialization(() =>
|
||||||
|
{
|
||||||
|
return serviceCollection.Where(x => x.ServiceType.GetInterfaces()
|
||||||
|
.Contains(typeof(IInitializable)) || x.ServiceType == typeof(IInitializable))
|
||||||
|
.GroupBy(x => x.ServiceType)
|
||||||
|
.Select(x => x.First())
|
||||||
|
.SelectMany(x => provider.GetServices(x.ServiceType)
|
||||||
|
.Select(x => (IInitializable?)x)).ToList();
|
||||||
|
}));
|
||||||
|
|
||||||
return serviceCollection;
|
return serviceCollection;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public static class IServiceFactoryExtensions
|
||||||
{
|
{
|
||||||
public static class IServiceFactoryExtensions
|
|
||||||
{
|
|
||||||
public static T? Create<T>(this IServiceFactory serviceFactory, params object?[] parameters)
|
public static T? Create<T>(this IServiceFactory serviceFactory, params object?[] parameters)
|
||||||
{
|
{
|
||||||
return serviceFactory.Create<T>(typeof(T), parameters);
|
return serviceFactory.Create<T>(typeof(T), parameters);
|
||||||
@@ -12,5 +12,4 @@
|
|||||||
ServiceFactoryDescriptor? descriptor = new(serviceFactory);
|
ServiceFactoryDescriptor? descriptor = new(serviceFactory);
|
||||||
return descriptor.Create(type);
|
return descriptor.Create(type);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
using Mediator;
|
using Mediator;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public class AppService : IHostedService
|
||||||
{
|
{
|
||||||
public class AppService : IHostedService
|
|
||||||
{
|
|
||||||
private readonly IMediator mediator;
|
private readonly IMediator mediator;
|
||||||
|
|
||||||
public AppService(IMediator mediator)
|
public AppService(IMediator mediator)
|
||||||
@@ -14,7 +14,7 @@ namespace Toolkit.Foundation
|
|||||||
|
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await mediator.Send(new Initialization());
|
await mediator.Send(new Initialize());
|
||||||
await mediator.Send(new Initialized());
|
await mediator.Send(new Initialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,5 +22,4 @@ namespace Toolkit.Foundation
|
|||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
{
|
|
||||||
public interface ICache
|
public interface ICache
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public interface IInitializable
|
||||||
|
{
|
||||||
|
Task InitializeAsync();
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public interface IInitialization
|
||||||
|
{
|
||||||
|
Task InitializeAsync();
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace Toolkit.Foundation
|
|
||||||
{
|
|
||||||
public interface IInitializer
|
|
||||||
{
|
|
||||||
Task InitializeAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,22 @@
|
|||||||
using Mediator;
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
public class Initialization : IInitialization
|
||||||
{
|
{
|
||||||
public record Initialization : IRequest;
|
private readonly Func<IEnumerable<IInitializable?>> factory;
|
||||||
|
|
||||||
|
public Initialization(Func<IEnumerable<IInitializable?>> factory)
|
||||||
|
{
|
||||||
|
this.factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task InitializeAsync()
|
||||||
|
{
|
||||||
|
foreach (IInitializable? initializer in factory())
|
||||||
|
{
|
||||||
|
if (initializer is not null)
|
||||||
|
{
|
||||||
|
await initializer.InitializeAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
using Mediator;
|
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
|
||||||
{
|
|
||||||
public class InitializationHandler : IRequestHandler<Initialization>
|
|
||||||
{
|
|
||||||
private readonly IEnumerable<IInitializer?> initializers;
|
|
||||||
|
|
||||||
public InitializationHandler(IEnumerable<IInitializer?> initializers)
|
|
||||||
{
|
|
||||||
this.initializers = initializers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Unit> Handle(Initialization request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
foreach (IInitializer? initializer in initializers)
|
|
||||||
{
|
|
||||||
if (initializer is not null)
|
|
||||||
{
|
|
||||||
await initializer.InitializeAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
using Mediator;
|
||||||
|
|
||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public record Initialize : IRequest;
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using Mediator;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public class InitializeHandler : IRequestHandler<Initialize>
|
||||||
|
{
|
||||||
|
private readonly IEnumerable<IInitializable?> initializers;
|
||||||
|
|
||||||
|
public InitializeHandler(IEnumerable<IInitializable?> initializers)
|
||||||
|
{
|
||||||
|
this.initializers = initializers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<Unit> Handle(Initialize request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
foreach (IInitializable? initializer in initializers)
|
||||||
|
{
|
||||||
|
if (initializer is not null)
|
||||||
|
{
|
||||||
|
Trace.WriteLine(initializer.GetType());
|
||||||
|
await initializer.InitializeAsync();
|
||||||
|
Trace.WriteLine("Done");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using Mediator;
|
using Mediator;
|
||||||
|
|
||||||
namespace Toolkit.Foundation
|
namespace Toolkit.Foundation;
|
||||||
{
|
|
||||||
public record class Initialized : IRequest;
|
public record class Initialized : IRequest;
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user