使用Actor Model保存驻留在POCO / DTO中的状态

时间:2015-10-02 08:49:05

标签: akka poco dto orleans actor-model

我正在寻找一些用例或代码示例,用于说明如何使用阻碍业务逻辑的Actor模型来保存驻留在简单DTO / POCO模型类中的状态。

由于

1 个答案:

答案 0 :(得分:1)

我只能回答奥尔良。

有些样本显示了持久状态所需的各个部分:

https://github.com/dotnet/orleans/tree/master/Samples/StorageProviders

基本上你创建了一个类来存储你的颗粒状态:

public class MyState : GrainState
{
  public string StringValue { get; set; }
  public int IntValue { get; set; }
  public DateTime DateTimeValue { get; set; }
  public Guid GuidValue { get; set; }
  public IGrain1 GrainValue { get; set; }
}

(好吧,这不是POCO)

然后你可以创建一个使用这个类的粒子作为它的状态:

[ StorageProvider( ProviderName = "myprovider" ) ]
public class Grain1 : Grain< MyState >, IGrain1
{
  public Task Set( string stringValue, int intValue, DateTime dateTimeValue, Guid guidValue, IGrain1 grainValue )
  {
    State.StringValue = stringValue;
    State.IntValue = intValue;
    State.DateTimeValue = dateTimeValue;
    State.GuidValue = guidValue;
    State.GrainValue = grainValue;
    return WriteStateAsync();
  }
}

用于实际存储状态的基础机制是配置选项。开箱即用的Azure表存储,但还有其他几个选项,包括Redis,Azure Blob存储和SQL Server。