Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Aevatar.Core/GAgentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public abstract partial class
private IStateDispatcher? StateDispatcher { get; set; }
protected AevatarOptions? AevatarOptions;

private DeepCopier? _copier;
public async Task ActivateAsync()
{
await Task.Yield();
Expand Down Expand Up @@ -245,7 +246,8 @@ public Task<TState> GetStateAsync()
}

public sealed override async Task OnActivateAsync(CancellationToken cancellationToken)
{
{
_copier = ServiceProvider.GetRequiredService<DeepCopier>();
StateDispatcher = ServiceProvider.GetService<IStateDispatcher>();
AevatarOptions = ServiceProvider.GetRequiredService<IOptions<AevatarOptions>>().Value;
try
Expand Down Expand Up @@ -353,10 +355,11 @@ private async Task InternalOnStateChangedAsync()
await HandleStateChangedAsync();
if (StateDispatcher != null)
{
var snapshot = _copier!.Copy(State);
await StateDispatcher.PublishSingleAsync(this.GetGrainId(),
new StateWrapper<TState>(this.GetGrainId(), State, Version));
new StateWrapper<TState>(this.GetGrainId(), snapshot, Version));
await StateDispatcher.PublishAsync(this.GetGrainId(),
new StateWrapper<TState>(this.GetGrainId(), State, Version));
new StateWrapper<TState>(this.GetGrainId(), snapshot, Version));
}
}

Expand Down
Loading