From 369e35962204d65269f92043741a8c7854e22114 Mon Sep 17 00:00:00 2001 From: Daniel Clark Date: Sat, 17 Dec 2022 20:27:52 +0000 Subject: [PATCH] Full removal of SourceGen Meditor. Will revisit in good time. --- Framework/Avalonia/Avalonia.csproj | 1 - Framework/Avalonia/Contents/ContentHandler.cs | 1 - .../Extensions/IHostBuilderExtensions.cs | 2 +- .../Avalonia/Markups/ContentExtension.cs | 1 - .../Avalonia/Markups/NavigateExtension.cs | 1 - .../Markups/NavigationRouteExtension.cs | 1 - .../ContentControlNavigationHandler.cs | 2 +- .../ContentDialogNavigationHandler.cs | 1 - .../Navigation/FrameNavigationHandler.cs | 2 +- .../Navigation/NavigateBackHandler.cs | 1 - .../Avalonia/Navigation/NavigateHandler.cs | 1 - Framework/Avalonia/Navigation/Navigation.cs | 2 +- .../Navigation/NavigationRouteHandler.cs | 1 - .../Configurations/ConfigurationChanged.cs | 2 +- .../ConfigurationInitializer.cs | 4 +- Framework/Foundation/Configurations/Write.cs | 4 +- .../Foundation/Configurations/WriteHandler.cs | 4 +- Framework/Foundation/Contents/Content.cs | 4 +- .../Contents/NamedContentFactory.cs | 2 +- .../Contents/TypedContentFactory.cs | 2 +- .../IServiceCollectionExtensions.cs | 3 +- Framework/Foundation/Foundation.csproj | 3 -- Framework/Foundation/Lifecycles/AppService.cs | 3 +- .../Lifecycles/CommandClassHandlerWrapper.cs | 4 +- Framework/Foundation/Lifecycles/ICommand.cs | 4 ++ .../Foundation/Lifecycles/ICommandHandler.cs | 8 +++ Framework/Foundation/Lifecycles/IMediator.cs | 12 +++++ Framework/Foundation/Lifecycles/IMessage.cs | 3 ++ .../Foundation/Lifecycles/INotification.cs | 3 ++ .../Lifecycles/INotificationHandler.cs | 6 +++ .../Lifecycles/IPipelineBehavior.cs | 10 ++++ Framework/Foundation/Lifecycles/IQuery.cs | 3 ++ .../Foundation/Lifecycles/IQueryHandler.cs | 6 +++ Framework/Foundation/Lifecycles/IRequest.cs | 5 ++ .../Foundation/Lifecycles/IRequestHandler.cs | 11 ++++ Framework/Foundation/Lifecycles/Initialize.cs | 3 +- .../Lifecycles/InitializeHandler.cs | 4 +- .../Foundation/Lifecycles/Initialized.cs | 4 +- Framework/Foundation/Lifecycles/Mediator.cs | 50 ++++--------------- .../Lifecycles/MessageHandlerDelegate.cs | 3 ++ .../Lifecycles/QueryClassHandlerWrapper.cs | 4 +- .../Lifecycles/RequestClassHandlerWrapper.cs | 4 +- Framework/Foundation/Lifecycles/Unit.cs | 26 ++++++++++ Framework/Foundation/Navigation/Navigate.cs | 3 +- .../Foundation/Navigation/NavigateBack.cs | 4 +- .../Foundation/Navigation/NavigationRoute.cs | 4 +- Framework/Foundation/Services/Create.cs | 4 +- .../Foundation/Services/ServiceCreator.cs | 2 +- .../Services/ServiceFactoryHandler.cs | 4 +- 49 files changed, 134 insertions(+), 108 deletions(-) create mode 100644 Framework/Foundation/Lifecycles/ICommand.cs create mode 100644 Framework/Foundation/Lifecycles/ICommandHandler.cs create mode 100644 Framework/Foundation/Lifecycles/IMediator.cs create mode 100644 Framework/Foundation/Lifecycles/IMessage.cs create mode 100644 Framework/Foundation/Lifecycles/INotification.cs create mode 100644 Framework/Foundation/Lifecycles/INotificationHandler.cs create mode 100644 Framework/Foundation/Lifecycles/IPipelineBehavior.cs create mode 100644 Framework/Foundation/Lifecycles/IQuery.cs create mode 100644 Framework/Foundation/Lifecycles/IQueryHandler.cs create mode 100644 Framework/Foundation/Lifecycles/IRequest.cs create mode 100644 Framework/Foundation/Lifecycles/IRequestHandler.cs create mode 100644 Framework/Foundation/Lifecycles/MessageHandlerDelegate.cs create mode 100644 Framework/Foundation/Lifecycles/Unit.cs diff --git a/Framework/Avalonia/Avalonia.csproj b/Framework/Avalonia/Avalonia.csproj index 63d5b85..8c89d88 100644 --- a/Framework/Avalonia/Avalonia.csproj +++ b/Framework/Avalonia/Avalonia.csproj @@ -9,7 +9,6 @@ - diff --git a/Framework/Avalonia/Contents/ContentHandler.cs b/Framework/Avalonia/Contents/ContentHandler.cs index d259885..d951361 100644 --- a/Framework/Avalonia/Contents/ContentHandler.cs +++ b/Framework/Avalonia/Contents/ContentHandler.cs @@ -1,5 +1,4 @@ using Avalonia; -using Mediator; using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Avalonia/Extensions/IHostBuilderExtensions.cs b/Framework/Avalonia/Extensions/IHostBuilderExtensions.cs index 32c8c83..300219e 100644 --- a/Framework/Avalonia/Extensions/IHostBuilderExtensions.cs +++ b/Framework/Avalonia/Extensions/IHostBuilderExtensions.cs @@ -7,7 +7,7 @@ namespace Toolkit.Framework.Avalonia; public static class IHostBuilderExtensions { - public static IHostBuilder ConfigureTemplates(this IHostBuilder hostBuilder, Action builderDelegate) + public static IHostBuilder ConfigureContents(this IHostBuilder hostBuilder, Action builderDelegate) { hostBuilder.ConfigureServices((hostBuilderContext, serviceCollection) => { diff --git a/Framework/Avalonia/Markups/ContentExtension.cs b/Framework/Avalonia/Markups/ContentExtension.cs index ff8cbd8..ac73389 100644 --- a/Framework/Avalonia/Markups/ContentExtension.cs +++ b/Framework/Avalonia/Markups/ContentExtension.cs @@ -3,7 +3,6 @@ using Avalonia.Controls; using Avalonia.Data; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; -using Mediator; using System.Diagnostics; using Toolkit.Framework.Foundation; diff --git a/Framework/Avalonia/Markups/NavigateExtension.cs b/Framework/Avalonia/Markups/NavigateExtension.cs index dd99cf4..5911911 100644 --- a/Framework/Avalonia/Markups/NavigateExtension.cs +++ b/Framework/Avalonia/Markups/NavigateExtension.cs @@ -2,7 +2,6 @@ using Avalonia.Controls; using Avalonia.Data; using Avalonia.Markup.Xaml; -using Mediator; using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Avalonia/Markups/NavigationRouteExtension.cs b/Framework/Avalonia/Markups/NavigationRouteExtension.cs index efe02db..b1adf7b 100644 --- a/Framework/Avalonia/Markups/NavigationRouteExtension.cs +++ b/Framework/Avalonia/Markups/NavigationRouteExtension.cs @@ -4,7 +4,6 @@ using Avalonia.Controls.Primitives; using Avalonia.Data; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; -using Mediator; using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Avalonia/Navigation/ContentControlNavigationHandler.cs b/Framework/Avalonia/Navigation/ContentControlNavigationHandler.cs index 78d6b2f..abbcde1 100644 --- a/Framework/Avalonia/Navigation/ContentControlNavigationHandler.cs +++ b/Framework/Avalonia/Navigation/ContentControlNavigationHandler.cs @@ -1,5 +1,5 @@ using Avalonia.Controls.Primitives; -using Mediator; +using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Avalonia/Navigation/ContentDialogNavigationHandler.cs b/Framework/Avalonia/Navigation/ContentDialogNavigationHandler.cs index 5fe2adc..0da3122 100644 --- a/Framework/Avalonia/Navigation/ContentDialogNavigationHandler.cs +++ b/Framework/Avalonia/Navigation/ContentDialogNavigationHandler.cs @@ -1,5 +1,4 @@ using FluentAvalonia.UI.Controls; -using Mediator; using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Avalonia/Navigation/FrameNavigationHandler.cs b/Framework/Avalonia/Navigation/FrameNavigationHandler.cs index 7428840..be039a2 100644 --- a/Framework/Avalonia/Navigation/FrameNavigationHandler.cs +++ b/Framework/Avalonia/Navigation/FrameNavigationHandler.cs @@ -1,6 +1,6 @@ using Avalonia.Controls.Primitives; using FluentAvalonia.UI.Navigation; -using Mediator; +using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Avalonia/Navigation/NavigateBackHandler.cs b/Framework/Avalonia/Navigation/NavigateBackHandler.cs index e937fef..1e4e4d3 100644 --- a/Framework/Avalonia/Navigation/NavigateBackHandler.cs +++ b/Framework/Avalonia/Navigation/NavigateBackHandler.cs @@ -1,7 +1,6 @@ using Avalonia.Controls; using Avalonia.Controls.Primitives; using FluentAvalonia.UI.Controls; -using Mediator; using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Avalonia/Navigation/NavigateHandler.cs b/Framework/Avalonia/Navigation/NavigateHandler.cs index 1bc580c..f5bb795 100644 --- a/Framework/Avalonia/Navigation/NavigateHandler.cs +++ b/Framework/Avalonia/Navigation/NavigateHandler.cs @@ -1,6 +1,5 @@ using Avalonia.Controls; using FluentAvalonia.UI.Controls; -using Mediator; using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Avalonia/Navigation/Navigation.cs b/Framework/Avalonia/Navigation/Navigation.cs index e695017..9728abb 100644 --- a/Framework/Avalonia/Navigation/Navigation.cs +++ b/Framework/Avalonia/Navigation/Navigation.cs @@ -1,5 +1,5 @@ using Avalonia.Controls.Primitives; -using Mediator; +using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Avalonia/Navigation/NavigationRouteHandler.cs b/Framework/Avalonia/Navigation/NavigationRouteHandler.cs index b38d259..144a717 100644 --- a/Framework/Avalonia/Navigation/NavigationRouteHandler.cs +++ b/Framework/Avalonia/Navigation/NavigationRouteHandler.cs @@ -1,6 +1,5 @@ using Avalonia.Controls.Primitives; using Avalonia.Interactivity; -using Mediator; using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Foundation/Configurations/ConfigurationChanged.cs b/Framework/Foundation/Configurations/ConfigurationChanged.cs index 90202ec..bd03b1e 100644 --- a/Framework/Foundation/Configurations/ConfigurationChanged.cs +++ b/Framework/Foundation/Configurations/ConfigurationChanged.cs @@ -1,3 +1,3 @@ namespace Toolkit.Framework.Foundation; -public record ConfigurationChanged(TConfiguration Configuration) where TConfiguration : class; \ No newline at end of file +public record ConfigurationChanged(TConfiguration Configuration) : INotification where TConfiguration : class; \ No newline at end of file diff --git a/Framework/Foundation/Configurations/ConfigurationInitializer.cs b/Framework/Foundation/Configurations/ConfigurationInitializer.cs index 49206d4..86a82ff 100644 --- a/Framework/Foundation/Configurations/ConfigurationInitializer.cs +++ b/Framework/Foundation/Configurations/ConfigurationInitializer.cs @@ -1,6 +1,4 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public class ConfigurationInitializer : IInitializable where TConfiguration : class, new() { diff --git a/Framework/Foundation/Configurations/Write.cs b/Framework/Foundation/Configurations/Write.cs index 8bebf84..04d9cb9 100644 --- a/Framework/Foundation/Configurations/Write.cs +++ b/Framework/Foundation/Configurations/Write.cs @@ -1,5 +1,3 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public record Write(Action UpdateDelegate) : IRequest where TConfiguration : class; \ No newline at end of file diff --git a/Framework/Foundation/Configurations/WriteHandler.cs b/Framework/Foundation/Configurations/WriteHandler.cs index 14c00fb..d5a96a7 100644 --- a/Framework/Foundation/Configurations/WriteHandler.cs +++ b/Framework/Foundation/Configurations/WriteHandler.cs @@ -1,6 +1,4 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public class WriteHandler : IRequestHandler> where TConfiguration : class { diff --git a/Framework/Foundation/Contents/Content.cs b/Framework/Foundation/Contents/Content.cs index 77b4033..b154d06 100644 --- a/Framework/Foundation/Contents/Content.cs +++ b/Framework/Foundation/Contents/Content.cs @@ -1,6 +1,4 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public record Content : IRequest { diff --git a/Framework/Foundation/Contents/NamedContentFactory.cs b/Framework/Foundation/Contents/NamedContentFactory.cs index b7c439c..51b0877 100644 --- a/Framework/Foundation/Contents/NamedContentFactory.cs +++ b/Framework/Foundation/Contents/NamedContentFactory.cs @@ -14,7 +14,7 @@ public class NamedContentFactory : INamedContentFactory this.serviceFactory = serviceFactory; } - public virtual object? Create(string name, params object[] parameters) + public virtual object? Create(string name, params object?[] parameters) { if (cache.TryGetValue(name, out object? data)) { diff --git a/Framework/Foundation/Contents/TypedContentFactory.cs b/Framework/Foundation/Contents/TypedContentFactory.cs index fe2c07f..6ed5d19 100644 --- a/Framework/Foundation/Contents/TypedContentFactory.cs +++ b/Framework/Foundation/Contents/TypedContentFactory.cs @@ -14,7 +14,7 @@ public class TypedContentFactory : ITypedContentFactory this.serviceFactory = serviceFactory; } - public virtual object? Create(Type type, params object[] parameters) + public object? Create(Type type, params object?[] parameters) { if (cache.TryGetValue(type, out object? data)) { diff --git a/Framework/Foundation/Extensions/IServiceCollectionExtensions.cs b/Framework/Foundation/Extensions/IServiceCollectionExtensions.cs index e3ddb71..16d6fae 100644 --- a/Framework/Foundation/Extensions/IServiceCollectionExtensions.cs +++ b/Framework/Foundation/Extensions/IServiceCollectionExtensions.cs @@ -1,5 +1,4 @@ -using Mediator; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; diff --git a/Framework/Foundation/Foundation.csproj b/Framework/Foundation/Foundation.csproj index 9e02892..58286b8 100644 --- a/Framework/Foundation/Foundation.csproj +++ b/Framework/Foundation/Foundation.csproj @@ -9,15 +9,12 @@ - - - diff --git a/Framework/Foundation/Lifecycles/AppService.cs b/Framework/Foundation/Lifecycles/AppService.cs index 94b8d8c..af5db1b 100644 --- a/Framework/Foundation/Lifecycles/AppService.cs +++ b/Framework/Foundation/Lifecycles/AppService.cs @@ -1,5 +1,4 @@ -using Mediator; -using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Hosting; namespace Toolkit.Framework.Foundation; diff --git a/Framework/Foundation/Lifecycles/CommandClassHandlerWrapper.cs b/Framework/Foundation/Lifecycles/CommandClassHandlerWrapper.cs index 828e6e3..064e5ae 100644 --- a/Framework/Foundation/Lifecycles/CommandClassHandlerWrapper.cs +++ b/Framework/Foundation/Lifecycles/CommandClassHandlerWrapper.cs @@ -1,6 +1,4 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public class CommandClassHandlerWrapper where TRequest : class, ICommand { diff --git a/Framework/Foundation/Lifecycles/ICommand.cs b/Framework/Foundation/Lifecycles/ICommand.cs new file mode 100644 index 0000000..7a93b34 --- /dev/null +++ b/Framework/Foundation/Lifecycles/ICommand.cs @@ -0,0 +1,4 @@ +namespace Toolkit.Framework.Foundation; + +public interface ICommand : IMessage { } +public interface ICommand : ICommand { } diff --git a/Framework/Foundation/Lifecycles/ICommandHandler.cs b/Framework/Foundation/Lifecycles/ICommandHandler.cs new file mode 100644 index 0000000..167dc24 --- /dev/null +++ b/Framework/Foundation/Lifecycles/ICommandHandler.cs @@ -0,0 +1,8 @@ +namespace Toolkit.Framework.Foundation; + +public interface ICommandHandler : ICommandHandler where TCommand : ICommand { } + +public interface ICommandHandler where TCommand : ICommand +{ + ValueTask Handle(TCommand command, CancellationToken cancellationToken); +} diff --git a/Framework/Foundation/Lifecycles/IMediator.cs b/Framework/Foundation/Lifecycles/IMediator.cs new file mode 100644 index 0000000..2d83080 --- /dev/null +++ b/Framework/Foundation/Lifecycles/IMediator.cs @@ -0,0 +1,12 @@ +namespace Toolkit.Framework.Foundation; + +public interface IMediator +{ + ValueTask Send(IRequest request, CancellationToken cancellationToken = default); + + ValueTask Send(ICommand command, CancellationToken cancellationToken = default); + + ValueTask Send(IQuery query, CancellationToken cancellationToken = default); + + ValueTask Send(object message, CancellationToken cancellationToken = default); +} diff --git a/Framework/Foundation/Lifecycles/IMessage.cs b/Framework/Foundation/Lifecycles/IMessage.cs new file mode 100644 index 0000000..66decab --- /dev/null +++ b/Framework/Foundation/Lifecycles/IMessage.cs @@ -0,0 +1,3 @@ +namespace Toolkit.Framework.Foundation; + +public interface IMessage { } diff --git a/Framework/Foundation/Lifecycles/INotification.cs b/Framework/Foundation/Lifecycles/INotification.cs new file mode 100644 index 0000000..838acf5 --- /dev/null +++ b/Framework/Foundation/Lifecycles/INotification.cs @@ -0,0 +1,3 @@ +namespace Toolkit.Framework.Foundation; + +public interface INotification : IMessage { } diff --git a/Framework/Foundation/Lifecycles/INotificationHandler.cs b/Framework/Foundation/Lifecycles/INotificationHandler.cs new file mode 100644 index 0000000..b99fae7 --- /dev/null +++ b/Framework/Foundation/Lifecycles/INotificationHandler.cs @@ -0,0 +1,6 @@ +namespace Toolkit.Framework.Foundation; + +public interface INotificationHandler where TNotification : INotification +{ + ValueTask Handle(TNotification notification, CancellationToken cancellationToken); +} diff --git a/Framework/Foundation/Lifecycles/IPipelineBehavior.cs b/Framework/Foundation/Lifecycles/IPipelineBehavior.cs new file mode 100644 index 0000000..00f7f7f --- /dev/null +++ b/Framework/Foundation/Lifecycles/IPipelineBehavior.cs @@ -0,0 +1,10 @@ +namespace Toolkit.Framework.Foundation; + +public interface IPipelineBehavior where TMessage : notnull, IMessage +{ + ValueTask Handle( + TMessage message, + CancellationToken cancellationToken, + MessageHandlerDelegate next + ); +} diff --git a/Framework/Foundation/Lifecycles/IQuery.cs b/Framework/Foundation/Lifecycles/IQuery.cs new file mode 100644 index 0000000..b351070 --- /dev/null +++ b/Framework/Foundation/Lifecycles/IQuery.cs @@ -0,0 +1,3 @@ +namespace Toolkit.Framework.Foundation; + +public interface IQuery : IMessage { } diff --git a/Framework/Foundation/Lifecycles/IQueryHandler.cs b/Framework/Foundation/Lifecycles/IQueryHandler.cs new file mode 100644 index 0000000..208db43 --- /dev/null +++ b/Framework/Foundation/Lifecycles/IQueryHandler.cs @@ -0,0 +1,6 @@ +namespace Toolkit.Framework.Foundation; + +public interface IQueryHandler where TQuery : IQuery +{ + ValueTask Handle(TQuery query, CancellationToken cancellationToken); +} diff --git a/Framework/Foundation/Lifecycles/IRequest.cs b/Framework/Foundation/Lifecycles/IRequest.cs new file mode 100644 index 0000000..6940a47 --- /dev/null +++ b/Framework/Foundation/Lifecycles/IRequest.cs @@ -0,0 +1,5 @@ +namespace Toolkit.Framework.Foundation; + +public interface IRequest : IRequest { } + +public interface IRequest : IMessage { } diff --git a/Framework/Foundation/Lifecycles/IRequestHandler.cs b/Framework/Foundation/Lifecycles/IRequestHandler.cs new file mode 100644 index 0000000..737d1d8 --- /dev/null +++ b/Framework/Foundation/Lifecycles/IRequestHandler.cs @@ -0,0 +1,11 @@ +namespace Toolkit.Framework.Foundation; + +public interface IRequestHandler : IRequestHandler where TRequest : IRequest +{ + +} + +public interface IRequestHandler where TRequest : IRequest +{ + ValueTask Handle(TRequest request, CancellationToken cancellationToken); +} \ No newline at end of file diff --git a/Framework/Foundation/Lifecycles/Initialize.cs b/Framework/Foundation/Lifecycles/Initialize.cs index c58a640..107d7c9 100644 --- a/Framework/Foundation/Lifecycles/Initialize.cs +++ b/Framework/Foundation/Lifecycles/Initialize.cs @@ -1,5 +1,4 @@ -using Mediator; - + namespace Toolkit.Framework.Foundation; public record Initialize : IRequest; \ No newline at end of file diff --git a/Framework/Foundation/Lifecycles/InitializeHandler.cs b/Framework/Foundation/Lifecycles/InitializeHandler.cs index b750e13..a35b75b 100644 --- a/Framework/Foundation/Lifecycles/InitializeHandler.cs +++ b/Framework/Foundation/Lifecycles/InitializeHandler.cs @@ -1,6 +1,4 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public class InitializeHandler : IRequestHandler { diff --git a/Framework/Foundation/Lifecycles/Initialized.cs b/Framework/Foundation/Lifecycles/Initialized.cs index 842880d..8205908 100644 --- a/Framework/Foundation/Lifecycles/Initialized.cs +++ b/Framework/Foundation/Lifecycles/Initialized.cs @@ -1,5 +1,3 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public record class Initialized : IRequest; \ No newline at end of file diff --git a/Framework/Foundation/Lifecycles/Mediator.cs b/Framework/Foundation/Lifecycles/Mediator.cs index 9c76897..b3989e3 100644 --- a/Framework/Foundation/Lifecycles/Mediator.cs +++ b/Framework/Foundation/Lifecycles/Mediator.cs @@ -1,49 +1,17 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public class Mediator : IMediator { - private readonly IServiceProvider factory; + private readonly IServiceFactory factory; - public Mediator(IServiceProvider factory) + public Mediator(IServiceFactory factory) { this.factory = factory; } - public IAsyncEnumerable CreateStream(IStreamQuery query, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public IAsyncEnumerable CreateStream(IStreamRequest request, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public IAsyncEnumerable CreateStream(IStreamCommand command, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public IAsyncEnumerable CreateStream(object request, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - public ValueTask Publish(TNotification notification, CancellationToken cancellationToken = default) where TNotification : INotification - { - throw new NotImplementedException(); - } - - public ValueTask Publish(object notification, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - public ValueTask Send(IRequest request, CancellationToken cancellationToken = default) { - dynamic? handler = factory.GetService(typeof(RequestClassHandlerWrapper<,>).MakeGenericType(request.GetType(), typeof(TResponse))); + dynamic? handler = factory.Create(typeof(RequestClassHandlerWrapper<,>).MakeGenericType(request.GetType(), typeof(TResponse))); if (handler is not null) { return handler.Handle((dynamic)request, cancellationToken); @@ -54,7 +22,7 @@ public class Mediator : IMediator public ValueTask Send(ICommand command, CancellationToken cancellationToken = default) { - dynamic? handler = factory.GetService(typeof(CommandClassHandlerWrapper<,>).MakeGenericType(command.GetType(), typeof(TResponse))); + dynamic? handler = factory.Create(typeof(CommandClassHandlerWrapper<,>).MakeGenericType(command.GetType(), typeof(TResponse))); if (handler is not null) { return handler.Handle((dynamic)command, cancellationToken); @@ -65,7 +33,7 @@ public class Mediator : IMediator public ValueTask Send(IQuery query, CancellationToken cancellationToken = default) { - dynamic? handler = factory.GetService(typeof(QueryClassHandlerWrapper<,>).MakeGenericType(query.GetType(), typeof(TResponse))); + dynamic? handler = factory.Create(typeof(QueryClassHandlerWrapper<,>).MakeGenericType(query.GetType(), typeof(TResponse))); if (handler is not null) { return handler.Handle((dynamic)query, cancellationToken); @@ -82,7 +50,7 @@ public class Mediator : IMediator { Type responseType = arguments[0]; - dynamic? handler = factory.GetService(typeof(RequestClassHandlerWrapper<,>).MakeGenericType(message.GetType(), responseType)); + dynamic? handler = factory.Create(typeof(RequestClassHandlerWrapper<,>).MakeGenericType(message.GetType(), responseType)); if (handler is not null) { return handler.Handle((dynamic)message, cancellationToken); @@ -96,7 +64,7 @@ public class Mediator : IMediator { Type responseType = arguments[0]; - dynamic? handler = factory.GetService(typeof(CommandClassHandlerWrapper<,>).MakeGenericType(message.GetType(), responseType)); + dynamic? handler = factory.Create(typeof(CommandClassHandlerWrapper<,>).MakeGenericType(message.GetType(), responseType)); if (handler is not null) { return handler.Handle((dynamic)message, cancellationToken); @@ -110,7 +78,7 @@ public class Mediator : IMediator { Type responseType = arguments[0]; - dynamic? handler = factory.GetService(typeof(QueryClassHandlerWrapper<,>).MakeGenericType(message.GetType(), responseType)); + dynamic? handler = factory.Create(typeof(QueryClassHandlerWrapper<,>).MakeGenericType(message.GetType(), responseType)); if (handler is not null) { return handler.Handle((dynamic)message, cancellationToken); diff --git a/Framework/Foundation/Lifecycles/MessageHandlerDelegate.cs b/Framework/Foundation/Lifecycles/MessageHandlerDelegate.cs new file mode 100644 index 0000000..f4a5c8d --- /dev/null +++ b/Framework/Foundation/Lifecycles/MessageHandlerDelegate.cs @@ -0,0 +1,3 @@ +namespace Toolkit.Framework.Foundation; + +public delegate ValueTask MessageHandlerDelegate(TMessage message, CancellationToken cancellationToken) where TMessage : notnull, IMessage; diff --git a/Framework/Foundation/Lifecycles/QueryClassHandlerWrapper.cs b/Framework/Foundation/Lifecycles/QueryClassHandlerWrapper.cs index 6f36b67..033b8cf 100644 --- a/Framework/Foundation/Lifecycles/QueryClassHandlerWrapper.cs +++ b/Framework/Foundation/Lifecycles/QueryClassHandlerWrapper.cs @@ -1,6 +1,4 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public class QueryClassHandlerWrapper where TRequest : class, IQuery { diff --git a/Framework/Foundation/Lifecycles/RequestClassHandlerWrapper.cs b/Framework/Foundation/Lifecycles/RequestClassHandlerWrapper.cs index 50d0fad..538033d 100644 --- a/Framework/Foundation/Lifecycles/RequestClassHandlerWrapper.cs +++ b/Framework/Foundation/Lifecycles/RequestClassHandlerWrapper.cs @@ -1,6 +1,4 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public class RequestClassHandlerWrapper where TRequest : class, IRequest { diff --git a/Framework/Foundation/Lifecycles/Unit.cs b/Framework/Foundation/Lifecycles/Unit.cs new file mode 100644 index 0000000..1caa6ca --- /dev/null +++ b/Framework/Foundation/Lifecycles/Unit.cs @@ -0,0 +1,26 @@ +namespace Toolkit.Framework.Foundation; + +public readonly struct Unit : IEquatable, IComparable, IComparable +{ + private static readonly Unit _value = new(); + + public static ref readonly Unit Value => ref _value; + + public static ValueTask ValueTask => new ValueTask(_value); + + public int CompareTo(Unit other) => 0; + + int IComparable.CompareTo(object? obj) => 0; + + public override int GetHashCode() => 0; + + public bool Equals(Unit other) => true; + + public override bool Equals(object? obj) => obj is Unit; + + public static bool operator ==(Unit _, Unit __) => true; + + public static bool operator !=(Unit _, Unit __) => false; + + public override string ToString() => "()"; +} diff --git a/Framework/Foundation/Navigation/Navigate.cs b/Framework/Foundation/Navigation/Navigate.cs index c60ae33..4288f34 100644 --- a/Framework/Foundation/Navigation/Navigate.cs +++ b/Framework/Foundation/Navigation/Navigate.cs @@ -1,5 +1,4 @@ -using Mediator; - + namespace Toolkit.Framework.Foundation; public record Navigate : IRequest diff --git a/Framework/Foundation/Navigation/NavigateBack.cs b/Framework/Foundation/Navigation/NavigateBack.cs index 8fc4fbf..93712e2 100644 --- a/Framework/Foundation/Navigation/NavigateBack.cs +++ b/Framework/Foundation/Navigation/NavigateBack.cs @@ -1,5 +1,3 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public record NavigateBack(object Route) : IRequest; \ No newline at end of file diff --git a/Framework/Foundation/Navigation/NavigationRoute.cs b/Framework/Foundation/Navigation/NavigationRoute.cs index bae308c..d27d350 100644 --- a/Framework/Foundation/Navigation/NavigationRoute.cs +++ b/Framework/Foundation/Navigation/NavigationRoute.cs @@ -1,5 +1,3 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public record NavigationRoute(string Name, object Route) : IRequest; \ No newline at end of file diff --git a/Framework/Foundation/Services/Create.cs b/Framework/Foundation/Services/Create.cs index 76023c9..494707f 100644 --- a/Framework/Foundation/Services/Create.cs +++ b/Framework/Foundation/Services/Create.cs @@ -1,5 +1,3 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public record Create(Type Type, params object?[] Parameters) : IRequest; diff --git a/Framework/Foundation/Services/ServiceCreator.cs b/Framework/Foundation/Services/ServiceCreator.cs index f4cc2d0..69aff32 100644 --- a/Framework/Foundation/Services/ServiceCreator.cs +++ b/Framework/Foundation/Services/ServiceCreator.cs @@ -2,7 +2,7 @@ public class ServiceCreator : IServiceCreator { - public virtual object Create(Func creator, params object[] parameters) + public object Create(Func creator, params object[] parameters) { return creator(typeof(T), parameters); } diff --git a/Framework/Foundation/Services/ServiceFactoryHandler.cs b/Framework/Foundation/Services/ServiceFactoryHandler.cs index e89ff98..13460ff 100644 --- a/Framework/Foundation/Services/ServiceFactoryHandler.cs +++ b/Framework/Foundation/Services/ServiceFactoryHandler.cs @@ -1,6 +1,4 @@ -using Mediator; - -namespace Toolkit.Framework.Foundation; +namespace Toolkit.Framework.Foundation; public class ServiceFactoryHandler : IRequestHandler {