wip
This commit is contained in:
@@ -37,6 +37,7 @@ public class AsyncHandlerInitialization<TMessage, THandler>(IServiceProvider pro
|
||||
foreach (IAsyncHandler<TMessage> handler in provider.GetServices<IAsyncHandler<TMessage>>())
|
||||
{
|
||||
handler.Handle(args.Message, args.CancellationToken);
|
||||
args.Reply(Unit.Value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,4 +34,12 @@ public static class IMessengerExtensions
|
||||
public static async Task<TResponse> SendAsync<TMessage, TResponse>(this IMessenger messenger,
|
||||
TMessage message) where TMessage : class =>
|
||||
await messenger.Send(new AsyncResponseEventArgs<TMessage, TResponse> { Message = message });
|
||||
|
||||
public static async Task SendAsync<TMessage>(this IMessenger messenger)
|
||||
where TMessage : class, new() =>
|
||||
await messenger.Send(new AsyncResponseEventArgs<TMessage, Unit> { Message = new TMessage() });
|
||||
|
||||
public static async Task SendAsync<TMessage>(this IMessenger messenger,
|
||||
TMessage message) where TMessage : class =>
|
||||
await messenger.Send(new AsyncResponseEventArgs<TMessage, Unit> { Message = message });
|
||||
}
|
||||
|
||||
@@ -43,12 +43,12 @@ public static class IServiceCollectionExtensions
|
||||
if (key is { Length: > 0 })
|
||||
{
|
||||
services.Add(new ServiceDescriptor(typeof(IAsyncHandler<TMessage>), key, typeof(THandler), lifetime));
|
||||
services.AddInitialization<AsyncHandlerInitialization<TMessage, IAsyncHandler<TMessage>>>(key);
|
||||
services.AddInitialization<AsyncHandlerKeyedInitialization<TMessage, IAsyncHandler<TMessage>>>(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
services.Add(new ServiceDescriptor(typeof(IAsyncHandler<TMessage>), typeof(THandler), lifetime));
|
||||
services.AddInitialization<AsyncHandlerKeyedInitialization<TMessage, IAsyncHandler<TMessage>>>();
|
||||
services.AddInitialization<AsyncHandlerInitialization<TMessage, IAsyncHandler<TMessage>>>();
|
||||
}
|
||||
|
||||
return services;
|
||||
|
||||
@@ -67,13 +67,15 @@ public partial class Observable(IServiceProvider provider,
|
||||
|
||||
protected override sealed void OnActivated()
|
||||
{
|
||||
base.OnActivated();
|
||||
Messenger.RegisterAll(this);
|
||||
Activated();
|
||||
}
|
||||
|
||||
protected override sealed void OnDeactivated()
|
||||
{
|
||||
base.OnDeactivated();
|
||||
Messenger.UnregisterAll(this);
|
||||
Dispose();
|
||||
|
||||
Deactivated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reactive.Disposables;
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
@@ -38,8 +36,6 @@ public abstract partial class ObservableCollection<TViewModel> :
|
||||
|
||||
private readonly Dictionary<string, object> trackedProperties = [];
|
||||
|
||||
private bool cleaning;
|
||||
|
||||
[ObservableProperty]
|
||||
private int count;
|
||||
|
||||
@@ -173,7 +169,6 @@ public abstract partial class ObservableCollection<TViewModel> :
|
||||
|
||||
public void Clear(bool disposeItems = false)
|
||||
{
|
||||
cleaning = true;
|
||||
if (disposeItems)
|
||||
{
|
||||
foreach (TViewModel item in this.ToList())
|
||||
@@ -184,12 +179,10 @@ public abstract partial class ObservableCollection<TViewModel> :
|
||||
}
|
||||
|
||||
ClearItems();
|
||||
cleaning = false;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
cleaning = true;
|
||||
foreach (TViewModel item in this.ToList())
|
||||
{
|
||||
Disposer.Dispose(item);
|
||||
@@ -197,7 +190,6 @@ public abstract partial class ObservableCollection<TViewModel> :
|
||||
}
|
||||
|
||||
ClearItems();
|
||||
cleaning = false;
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
@@ -222,8 +214,8 @@ public abstract partial class ObservableCollection<TViewModel> :
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
Disposer.Dispose(this);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public IEnumerator<TViewModel> GetEnumerator() =>
|
||||
@@ -471,7 +463,7 @@ public abstract partial class ObservableCollection<TViewModel> :
|
||||
Disposer.Add(this, item);
|
||||
Disposer.Add(item, Disposable.Create(() =>
|
||||
{
|
||||
if (item is IDisposable && !cleaning)
|
||||
if (item is IDisposable)
|
||||
{
|
||||
if (item is IList collection)
|
||||
{
|
||||
@@ -487,13 +479,15 @@ public abstract partial class ObservableCollection<TViewModel> :
|
||||
|
||||
protected override sealed void OnActivated()
|
||||
{
|
||||
base.OnActivated();
|
||||
Messenger.RegisterAll(this);
|
||||
Activated();
|
||||
}
|
||||
|
||||
protected override sealed void OnDeactivated()
|
||||
{
|
||||
base.OnDeactivated();
|
||||
Messenger.UnregisterAll(this);
|
||||
Dispose();
|
||||
|
||||
Deactivated();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,4 +7,4 @@ public record Update
|
||||
|
||||
public static UpdateEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,4 @@ public record UpdateEventArgs<TSender>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Updated
|
||||
{
|
||||
public static UpdatedEventArgs<TValue> As<TValue>(TValue value) =>
|
||||
new(value);
|
||||
|
||||
public static UpdatedEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record UpdatedEventArgs<TSender>
|
||||
{
|
||||
public TSender? Sender { get; }
|
||||
|
||||
public UpdatedEventArgs(TSender sender)
|
||||
{
|
||||
Sender = sender;
|
||||
}
|
||||
|
||||
public UpdatedEventArgs()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user