From 29509e9d7a01ac2df8d3f1d62ce8e2b73cce9ab3 Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Wed, 5 Jun 2024 19:18:17 +0100 Subject: [PATCH] WIP --- Toolkit.Foundation/Aggregate.cs | 10 --- Toolkit.Foundation/AggregateEventArgs.cs | 7 -- Toolkit.Foundation/AggregateExpression.cs | 3 - Toolkit.Foundation/ComponentBuilder.cs | 2 - Toolkit.Foundation/Create.cs | 4 +- Toolkit.Foundation/CreateEventArgs.cs | 2 +- Toolkit.Foundation/DefaultHostBuilder.cs | 2 - Toolkit.Foundation/HandlerWrapper.cs | 2 +- Toolkit.Foundation/IIndexable.cs | 6 ++ .../IServiceCollectionExtensions.cs | 3 +- .../ISynchronizationCollection.cs | 6 ++ .../{IAggregate.cs => ISynchronize.cs} | 2 +- Toolkit.Foundation/ObservableCollection.cs | 67 ++++--------------- Toolkit.Foundation/Synchronize.cs | 10 +++ Toolkit.Foundation/SynchronizeEventArgs.cs | 7 ++ Toolkit.Foundation/SynchronizeExpression.cs | 3 + 16 files changed, 51 insertions(+), 85 deletions(-) delete mode 100644 Toolkit.Foundation/Aggregate.cs delete mode 100644 Toolkit.Foundation/AggregateEventArgs.cs delete mode 100644 Toolkit.Foundation/AggregateExpression.cs create mode 100644 Toolkit.Foundation/IIndexable.cs create mode 100644 Toolkit.Foundation/ISynchronizationCollection.cs rename Toolkit.Foundation/{IAggregate.cs => ISynchronize.cs} (53%) create mode 100644 Toolkit.Foundation/Synchronize.cs create mode 100644 Toolkit.Foundation/SynchronizeEventArgs.cs create mode 100644 Toolkit.Foundation/SynchronizeExpression.cs diff --git a/Toolkit.Foundation/Aggregate.cs b/Toolkit.Foundation/Aggregate.cs deleted file mode 100644 index b051bc9..0000000 --- a/Toolkit.Foundation/Aggregate.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Toolkit.Foundation; - -public record Aggregate -{ - public static AggerateEventArgs As(TOptions options) - where TOptions : class => new(options); - - public static AggerateEventArgs As() => - new(); -} diff --git a/Toolkit.Foundation/AggregateEventArgs.cs b/Toolkit.Foundation/AggregateEventArgs.cs deleted file mode 100644 index eff0223..0000000 --- a/Toolkit.Foundation/AggregateEventArgs.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Toolkit.Foundation; - -public record AggerateEventArgs(TValue? Value = default) : - IAggregate; - -public record AggerateEventArgs : - IAggregate; \ No newline at end of file diff --git a/Toolkit.Foundation/AggregateExpression.cs b/Toolkit.Foundation/AggregateExpression.cs deleted file mode 100644 index 3c70c3e..0000000 --- a/Toolkit.Foundation/AggregateExpression.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace Toolkit.Foundation; - -public record AggregateExpression(IAggregate Value, object? Key = null); diff --git a/Toolkit.Foundation/ComponentBuilder.cs b/Toolkit.Foundation/ComponentBuilder.cs index d1c0da8..b3dc932 100644 --- a/Toolkit.Foundation/ComponentBuilder.cs +++ b/Toolkit.Foundation/ComponentBuilder.cs @@ -45,8 +45,6 @@ public class ComponentBuilder : services.AddHandler(); services.AddHandler(); - - services.AddTransient(); }); } diff --git a/Toolkit.Foundation/Create.cs b/Toolkit.Foundation/Create.cs index 25f55c0..72b7fea 100644 --- a/Toolkit.Foundation/Create.cs +++ b/Toolkit.Foundation/Create.cs @@ -2,9 +2,9 @@ public record Create { - public static CreateEventArgs As(TValue value) => + public static CreateEventArgs As(TValue value, params object[] Parameters) => new(value); - public static CreateEventArgs As() where TValue : new() => + public static CreateEventArgs As(params object[] Parameters) where TValue : new() => new(new TValue()); } \ No newline at end of file diff --git a/Toolkit.Foundation/CreateEventArgs.cs b/Toolkit.Foundation/CreateEventArgs.cs index 58ced3a..d83845a 100644 --- a/Toolkit.Foundation/CreateEventArgs.cs +++ b/Toolkit.Foundation/CreateEventArgs.cs @@ -1,3 +1,3 @@ namespace Toolkit.Foundation; -public record CreateEventArgs(TValue Value); \ No newline at end of file +public record CreateEventArgs(TValue Value, params object[] Parameters); \ No newline at end of file diff --git a/Toolkit.Foundation/DefaultHostBuilder.cs b/Toolkit.Foundation/DefaultHostBuilder.cs index 8e50993..6318d9b 100644 --- a/Toolkit.Foundation/DefaultHostBuilder.cs +++ b/Toolkit.Foundation/DefaultHostBuilder.cs @@ -65,8 +65,6 @@ public class DefaultHostBuilder : services.AddHandler(); services.AddHandler(); - services.AddTransient(); - services.AddInitializer(); services.AddHostedService(); }); diff --git a/Toolkit.Foundation/HandlerWrapper.cs b/Toolkit.Foundation/HandlerWrapper.cs index e1f464d..ffd1d13 100644 --- a/Toolkit.Foundation/HandlerWrapper.cs +++ b/Toolkit.Foundation/HandlerWrapper.cs @@ -2,7 +2,7 @@ public class HandlerWrapper(IHandler handler, IEnumerable> pipelineBehaviours) - where TRequest : class + where TRequest : notnull { private readonly IEnumerable> pipelineBehaviours = pipelineBehaviours.Reverse(); diff --git a/Toolkit.Foundation/IIndexable.cs b/Toolkit.Foundation/IIndexable.cs new file mode 100644 index 0000000..dcf42af --- /dev/null +++ b/Toolkit.Foundation/IIndexable.cs @@ -0,0 +1,6 @@ +namespace Toolkit.Foundation; + +public interface IIndexable +{ + public int Index { get; } +} \ No newline at end of file diff --git a/Toolkit.Foundation/IServiceCollectionExtensions.cs b/Toolkit.Foundation/IServiceCollectionExtensions.cs index a5a779f..73814e3 100644 --- a/Toolkit.Foundation/IServiceCollectionExtensions.cs +++ b/Toolkit.Foundation/IServiceCollectionExtensions.cs @@ -106,8 +106,7 @@ public static class IServiceCollectionExtensions } if (key is not null) - { - + { services.Add(new ServiceDescriptor(wrapperType, key, (provider, key) => provider.GetService()?.Create(wrapperType, provider.GetRequiredKeyedService(key), diff --git a/Toolkit.Foundation/ISynchronizationCollection.cs b/Toolkit.Foundation/ISynchronizationCollection.cs new file mode 100644 index 0000000..34ddd27 --- /dev/null +++ b/Toolkit.Foundation/ISynchronizationCollection.cs @@ -0,0 +1,6 @@ +namespace Toolkit.Foundation; + +public interface ISynchronizationCollection +{ + int IndexOf(TItem item); +} diff --git a/Toolkit.Foundation/IAggregate.cs b/Toolkit.Foundation/ISynchronize.cs similarity index 53% rename from Toolkit.Foundation/IAggregate.cs rename to Toolkit.Foundation/ISynchronize.cs index 8ca8471..b75dcb4 100644 --- a/Toolkit.Foundation/IAggregate.cs +++ b/Toolkit.Foundation/ISynchronize.cs @@ -1,3 +1,3 @@ namespace Toolkit.Foundation; -public interface IAggregate; \ No newline at end of file +public interface ISynchronize; \ No newline at end of file diff --git a/Toolkit.Foundation/ObservableCollection.cs b/Toolkit.Foundation/ObservableCollection.cs index 1682f1d..57b1f85 100644 --- a/Toolkit.Foundation/ObservableCollection.cs +++ b/Toolkit.Foundation/ObservableCollection.cs @@ -6,40 +6,6 @@ using System.Reactive.Disposables; namespace Toolkit.Foundation; -public interface IIndexable -{ - int Index { get; } -} - -public interface ICollectionSynchronization - where TItem : notnull -{ - int IndexOf(TItem item); -} - -public interface ICollectionSynchronizer -{ - void Set(ICollectionSynchronization collection) - where TItem : notnull; -} - -public class CollectionSynchronizer(IServiceProvider serviceProvider) : - ICollectionSynchronizer -{ - private readonly IServiceProvider serviceProvider = serviceProvider; - - public void Set(ICollectionSynchronization collection) - where TItem : notnull - { - if (serviceProvider.GetService>>() - is IDecoratorService> decoratorService) - { - decoratorService.Set(collection); - } - } -} - - public partial class ObservableCollection : ObservableObject, IObservableCollectionViewModel, @@ -52,7 +18,7 @@ public partial class ObservableCollection : IList, IReadOnlyList, INotifyCollectionChanged, - ICollectionSynchronization, + ISynchronizationCollection, IServiceProviderRequired, IServiceFactoryRequired, IMediatorRequired, @@ -89,16 +55,13 @@ public partial class ObservableCollection : [ObservableProperty] private TItem? selectedItem; - public ObservableCollection(ICollectionSynchronizer synchronizer, - IServiceProvider provider, + public ObservableCollection(IServiceProvider provider, IServiceFactory factory, IMediator mediator, IPublisher publisher, ISubscription subscriber, IDisposer disposer) { - synchronizer.Set(this); - Provider = provider; Factory = factory; Mediator = mediator; @@ -111,8 +74,7 @@ public partial class ObservableCollection : collection.CollectionChanged += OnCollectionChanged; } - public ObservableCollection(ICollectionSynchronizer synchronizer, - IServiceProvider provider, + public ObservableCollection(IServiceProvider provider, IServiceFactory factory, IMediator mediator, IPublisher publisher, @@ -120,8 +82,6 @@ public partial class ObservableCollection : IDisposer disposer, IEnumerable items) { - synchronizer.Set(this); - Provider = provider; Factory = factory; Mediator = mediator; @@ -139,6 +99,7 @@ public partial class ObservableCollection : public event NotifyCollectionChangedEventHandler? CollectionChanged; public event EventHandler? DeactivateHandler; + public IDisposer Disposer { get; private set; } public IServiceFactory Factory { get; private set; } @@ -240,11 +201,11 @@ public partial class ObservableCollection : Clear(); } - AggregateExpression expression = BuildAggregateExpression(); + SynchronizeExpression expression = BuildAggregateExpression(); Publisher.PublishUI(expression.Value, expression.Key); } - public void Fetch(Func aggregateDelegate, + public void Fetch(Func aggregateDelegate, bool reset = false) { if (reset) @@ -252,7 +213,7 @@ public partial class ObservableCollection : Clear(); } - AggregateExpression expression = aggregateDelegate.Invoke(); + SynchronizeExpression expression = aggregateDelegate.Invoke(); Publisher.PublishUI(expression.Value, expression.Key); } @@ -616,8 +577,8 @@ public partial class ObservableCollection : collection.Insert(index > Count ? Count : index, item); } - protected virtual AggregateExpression BuildAggregateExpression() => - new(new AggerateEventArgs()); + protected virtual SynchronizeExpression BuildAggregateExpression() => + new(new SynchronizeEventArgs()); protected virtual void RemoveItem(int index) => collection.RemoveAt(index); @@ -664,12 +625,11 @@ public partial class ObservableCollection : } } -public partial class ObservableCollection(ICollectionSynchronizer synchronizer, - IServiceProvider provider, +public partial class ObservableCollection(IServiceProvider provider, IServiceFactory factory, IMediator mediator, IPublisher publisher, - ISubscription subscriber, IDisposer disposer) : ObservableCollection(synchronizer, provider, factory, mediator, publisher, subscriber, disposer) + ISubscription subscriber, IDisposer disposer) : ObservableCollection(provider, factory, mediator, publisher, subscriber, disposer) where TViewModel : notnull, IDisposable { @@ -677,11 +637,10 @@ public partial class ObservableCollection(ICollectionSynchro private TValue? value; } -public class ObservableCollection(ICollectionSynchronizer synchronizer, - IServiceProvider provider, +public class ObservableCollection(IServiceProvider provider, IServiceFactory factory, IMediator mediator, IPublisher publisher, ISubscription subscriber, IDisposer disposer) : - ObservableCollection(synchronizer, provider, factory, mediator, publisher, subscriber, disposer); \ No newline at end of file + ObservableCollection(provider, factory, mediator, publisher, subscriber, disposer); \ No newline at end of file diff --git a/Toolkit.Foundation/Synchronize.cs b/Toolkit.Foundation/Synchronize.cs new file mode 100644 index 0000000..93f7e6a --- /dev/null +++ b/Toolkit.Foundation/Synchronize.cs @@ -0,0 +1,10 @@ +namespace Toolkit.Foundation; + +public record Synchronize +{ + public static SynchronizeEventArgs As(TOptions options) + where TOptions : class => new(options); + + public static SynchronizeEventArgs As() => + new(); +} diff --git a/Toolkit.Foundation/SynchronizeEventArgs.cs b/Toolkit.Foundation/SynchronizeEventArgs.cs new file mode 100644 index 0000000..909575e --- /dev/null +++ b/Toolkit.Foundation/SynchronizeEventArgs.cs @@ -0,0 +1,7 @@ +namespace Toolkit.Foundation; + +public record SynchronizeEventArgs(TValue? Value = default) : + ISynchronize; + +public record SynchronizeEventArgs() : + ISynchronize; \ No newline at end of file diff --git a/Toolkit.Foundation/SynchronizeExpression.cs b/Toolkit.Foundation/SynchronizeExpression.cs new file mode 100644 index 0000000..a3106aa --- /dev/null +++ b/Toolkit.Foundation/SynchronizeExpression.cs @@ -0,0 +1,3 @@ +namespace Toolkit.Foundation; + +public record SynchronizeExpression(ISynchronize Value, object? Key = null);