orleans - 有效地从 Orleans Grain 获取状态
问题描述
我在奥尔良为比赛的球员准备了一粒粮食。玩家有几个我想在客户端直接访问的属性。是否有可能,是否有效,将这些作为公共财产是否有意义?或者,我是否应该有一个 GetAllState 方法,该方法返回一个 DTO,其中包含谷物中这些属性的当前值?
public interface IPlayerGrain : IGrainWithIntegerKey
{
// Individual public properties to access grain state?
string Name { get; }
int Score { get; }
int Health { get; }
// Or, get all the current grain state as DTO?
Task<PlayerState> GetAllState();
}
根据我目前的理解,我认为我将需要使用 GetAllState,因为我认为任何与谷物的通信都需要通过一种方法,这可能会在孤岛之间传递。因此,您可能希望最小化传递的消息数量,并且不想传递三个消息来获取名称、分数和健康。或者,消息传递是否很便宜,而不是我应该担心做太多事情?在我的示例中,我只包含了 3 个属性,但在我的真实游戏中还会有更多。
但是,我真的不喜欢拥有一个只是谷物内部属性副本的贫血 DTO 模型的想法。
所以我想知道是否有更好的方法,或者在奥尔良这种事情的首选模式?
解决方案
Introduction of a complex return type to minimize roundtrips is a valid solution.
However, I wouldn't return the whole internal state, as I assume that not all the clients need all the data all the time. It may also be a sign that you have a business logic implemented outside of the grains and you should move it into the grain.
推荐阅读
- c# - 递归,不能让嵌套的self对象为null,为什么会这样?
- flutter - Flutter 从 sqllite 中删除所有行
- python - 无法使用烧瓶在html页面上显示上传文件的内容
- javascript - Flask-Cors 不工作 Nuxt + Flask(使用 JWT)
- laravel - Laravel Livewire 2.x 是表格行点击事件
- sql - T-SQL 中的 FIFO 利润计算
- python - 堆叠数组的 Numpy 点积
- c++ - 使用浮点常量进行设置和检查
- android - 在 Android 上获取蓝牙地址
- python - 轴必须设置“频率”才能转换为周期 | 季节性_分解