Switch out dotnet ctk messenger for source gen Meditor
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Mediator;
|
||||
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
public class ConfigurationInitializer<TConfiguration> : IInitializer where TConfiguration : class, new()
|
||||
{
|
||||
private readonly TConfiguration configuration;
|
||||
private readonly IMessenger messenger;
|
||||
private readonly IMediator mediator;
|
||||
|
||||
public ConfigurationInitializer(TConfiguration configuration,
|
||||
IMessenger messenger)
|
||||
IMediator mediator)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.messenger = messenger;
|
||||
this.mediator = mediator;
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
messenger.Send(configuration);
|
||||
await mediator.Send(configuration);
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Toolkit.Foundation
|
||||
using Mediator;
|
||||
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
public record Write<TConfiguration>(string Section, Action<TConfiguration> UpdateDelegate) where TConfiguration : class;
|
||||
public abstract record Write<TConfiguration>(string Section, Action<TConfiguration> UpdateDelegate) : IRequest where TConfiguration : class;
|
||||
}
|
||||
|
||||
@@ -1,28 +1,30 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Mediator;
|
||||
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
public class WriteHandler<TConfiguration> : IRecipient<Write<TConfiguration>> where TConfiguration : class
|
||||
public class WriteHandler<TConfiguration> : IRequestHandler<Write<TConfiguration>> where TConfiguration : class
|
||||
{
|
||||
private readonly IMessenger messenger;
|
||||
private readonly IMediator mediator;
|
||||
private readonly TConfiguration configuration;
|
||||
private readonly IConfigurationWriter<TConfiguration> writer;
|
||||
|
||||
public WriteHandler(TConfiguration configuration,
|
||||
IConfigurationWriter<TConfiguration> writer,
|
||||
IMessenger messenger)
|
||||
IMediator mediator)
|
||||
{
|
||||
this.messenger = messenger;
|
||||
this.mediator = mediator;
|
||||
this.configuration = configuration;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public void Receive(Write<TConfiguration> request)
|
||||
public async ValueTask<Unit> Handle(Write<TConfiguration> request, CancellationToken cancellationToken)
|
||||
{
|
||||
request.UpdateDelegate.Invoke(configuration);
|
||||
writer.Write(request.Section, configuration);
|
||||
|
||||
messenger.Send(new ConfigurationChanged<TConfiguration>(configuration));
|
||||
await mediator.Send(new ConfigurationChanged<TConfiguration>(configuration), cancellationToken);
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddFoundation(this IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection.AddSingleton<IServiceFactory>(provider => new ServiceFactory(provider.GetService, (instanceType, parameters) => ActivatorUtilities.CreateInstance(provider, instanceType, parameters!)));
|
||||
|
||||
serviceCollection
|
||||
.AddSingleton<IInitialization, Initialization>(provider => new Initialization(() =>
|
||||
{
|
||||
return serviceCollection.Where(x => x.ServiceType.GetInterfaces()
|
||||
.Contains(typeof(IInitializer)) || x.ServiceType == typeof(IInitializer))
|
||||
.GroupBy(x => x.ServiceType)
|
||||
.Select(x => x.First())
|
||||
.SelectMany(x => provider.GetServices(x.ServiceType)
|
||||
.Select(x => (IInitializer?)x)).ToList();
|
||||
}));
|
||||
|
||||
return serviceCollection;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,23 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Mediator;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
public class AppService : IHostedService
|
||||
{
|
||||
private readonly IMessenger messenger;
|
||||
private readonly IMediator mediator;
|
||||
private readonly IInitialization initialization;
|
||||
|
||||
public AppService(IMessenger messenger,
|
||||
public AppService(IMediator mediator,
|
||||
IInitialization initialization)
|
||||
{
|
||||
this.messenger = messenger;
|
||||
this.mediator = mediator;
|
||||
this.initialization = initialization;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
messenger.Send(new Initialize());
|
||||
await mediator.Send(new Initialize());
|
||||
await initialization.InitializeAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Toolkit.Foundation
|
||||
using Mediator;
|
||||
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
public record class Initialize;
|
||||
public record class Initialize : IRequest;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
public interface INavigationRouter
|
||||
public interface INavigationRouter : IInitializer
|
||||
{
|
||||
void Navigate(Navigate args);
|
||||
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
|
||||
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
public class NavigateHandler : IRecipient<Navigate>
|
||||
{
|
||||
private readonly IMessenger messenger;
|
||||
//public class NavigateHandler : IRecipient<Navigate>
|
||||
//{
|
||||
// private readonly IMessenger messenger;
|
||||
|
||||
public NavigateHandler(IMessenger messenger)
|
||||
{
|
||||
this.messenger = messenger;
|
||||
}
|
||||
// public NavigateHandler(IMessenger messenger)
|
||||
// {
|
||||
// this.messenger = messenger;
|
||||
// }
|
||||
|
||||
public void Receive(Navigate request)
|
||||
{
|
||||
messenger.Send(request);
|
||||
}
|
||||
}
|
||||
// public void Receive(Navigate request)
|
||||
// {
|
||||
// messenger.Send(request);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -1,30 +1,30 @@
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
public class Navigated<TContent, TDataContext> where TContent : class where TDataContext : class
|
||||
public class Navigated<TTemplate, TContent> where TTemplate : class where TContent : class
|
||||
{
|
||||
public Navigated()
|
||||
{
|
||||
}
|
||||
|
||||
public Navigated(TContent content, TDataContext dataContext, IDictionary<string, object>? parameters = null)
|
||||
public Navigated(TTemplate template, TContent content, IDictionary<string, object>? parameters = null)
|
||||
{
|
||||
Template = template;
|
||||
Content = content;
|
||||
DataContext = dataContext;
|
||||
Parameters = parameters;
|
||||
}
|
||||
|
||||
public TContent? Content { get; }
|
||||
public TTemplate? Template { get; }
|
||||
|
||||
public TDataContext? DataContext { get; }
|
||||
public TContent? Content { get; }
|
||||
|
||||
public IDictionary<string, object>? Parameters { get; }
|
||||
}
|
||||
|
||||
public class Navigated
|
||||
{
|
||||
public static Navigated<TTemplate, TDataTemplate> Create<TTemplate, TDataTemplate>(TTemplate content, TDataTemplate dataContext, IDictionary<string, object>? parameters = null) where TTemplate : class where TDataTemplate : class
|
||||
public static Navigated<TTemplate, TContent> Create<TTemplate, TContent>(TTemplate template, TContent? content, IDictionary<string, object>? parameters = null) where TTemplate : class where TContent : class
|
||||
{
|
||||
return new Navigated<TTemplate, TDataTemplate>(content, dataContext, parameters);
|
||||
return new Navigated<TTemplate, TContent>(template, content, parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JsonPatch.Net" Version="2.0.4" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0-preview1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="Mediator.Abstractions" Version="2.1.0-preview.5" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user