mirror of https://github.com/dapr/quickstarts.git
Merge pull request #961 from WhitWaldo/updated-actor-csharp-quickstart-language
Clarified actor state persistence description
This commit is contained in:
commit
d718efec20
|
|
@ -36,7 +36,7 @@ internal class SmokeDetectorActor : Actor, ISmartDevice
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override Task OnDeactivateAsync()
|
protected override Task OnDeactivateAsync()
|
||||||
{
|
{
|
||||||
// Provides Opportunity to perform optional cleanup.
|
// Provides opportunity to perform optional cleanup.
|
||||||
Console.WriteLine($"Deactivating actor id: {Id}");
|
Console.WriteLine($"Deactivating actor id: {Id}");
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
@ -47,9 +47,12 @@ internal class SmokeDetectorActor : Actor, ISmartDevice
|
||||||
/// <param name="data">the user-defined MyData which will be stored into state store as "device_data" state</param>
|
/// <param name="data">the user-defined MyData which will be stored into state store as "device_data" state</param>
|
||||||
public async Task<string> SetDataAsync(SmartDeviceData data)
|
public async Task<string> SetDataAsync(SmartDeviceData data)
|
||||||
{
|
{
|
||||||
// Data is saved to configured state store *implicitly* after each method execution by Actor's runtime.
|
// This set state action can happen along other state changing operations in each actor method and those changes will be maintained
|
||||||
// Data can also be saved *explicitly* by calling this.StateManager.SaveStateAsync();
|
// in a local cache to be committed as a single transaction to the backing store when the method has completed. As such, there is
|
||||||
// State to be saved must be DataContract serializable.
|
// no need to (and in fact makes your code less transactional) call `this.StateManager.SaveStateAsync()` as it will be automatically
|
||||||
|
// invoked by the actor runtime following the conclusion of this method as part of the internal `OnPostActorMethodAsyncInternal` method.
|
||||||
|
|
||||||
|
// Note also that all saved state must be DataContract serializable.
|
||||||
await StateManager.SetStateAsync<SmartDeviceData>(
|
await StateManager.SetStateAsync<SmartDeviceData>(
|
||||||
deviceDataKey,
|
deviceDataKey,
|
||||||
data);
|
data);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue