EventAggregator 替代品

问题描述 投票:0回答:4

我一直在尝试使用此版本的 EventAggregator here

我一直在 Blazor Server 应用程序中使用它,该应用程序是使用 EventAggregator 的旧 Silverlight 应用程序的重写。然而,我遇到了很多问题。最新的它不会在应该触发事件时触发事件(不知道为什么它不能正常工作)。

无论如何,我正在寻找替代模式。

我正在寻找一种方法来告诉多个组件“CurrentCustomer”已更改,以便组件可以自行更新。

有推荐的模式或方法吗?

c# blazor blazor-server-side
4个回答
1
投票

这是我找到的 Blazor 唯一的 EventAggregator:https://mikaelkoskinen.net/post/blazor-eventaggregator-2-0-0-auto-refresh

唯一值得注意的是,当前默认如下:

builder.Services.AddScoped<EventAggregator.Blazor.IEventAggregator, EventAggregator.Blazor.EventAggregator>();//Use this.
//builder.Services.AddEventAggregator(); Not this. It adds it as a singleton which is NOT what we want. Change requested of author. The Events will be propagated to every user everywhere, instead of just the current user.

1
投票

2 年后,我现在使用了一种不同于尝试触发和捕捉事件的方法。事件会导致内存问题,并且在 Blazor Server 这样的基于组件的环境中无法真正工作。

我没有使用事件,而是使用内置的级联参数将参数向下传递到需要它们的所有组件。

因此,例如,如果您有一个 CurrentCustomer 的级联参数,它将沿着组件的层次结构传播该参数。


0
投票

到目前为止,我发现的最好的东西是 StateContainer,如下所述:here 它只是一个保存状态的简单类,您可以订阅它的事件。


0
投票

在 Blazor 中使用 Fluxor 进行状态管理

© www.soinside.com 2019 - 2024. All rights reserved.