Durable Entities bring actor-model programming to Azure Functions. Store state reliably without a database.
Entity Example
[FunctionName(nameof(Counter))]
public static void Counter([EntityTrigger] IDurableEntityContext ctx)
{
int current = ctx.GetState<int>();
switch (ctx.OperationName.ToLower())
{
case "add": current += ctx.GetInput<int>(); break;
case "reset": current = 0; break;
case "get": ctx.Return(current); break;
}
ctx.SetState(current);
}
Calling Entities
var entityId = new EntityId(nameof(Counter), "myCounter");
await client.SignalEntityAsync(entityId, "add", 5);
var state = await client.ReadEntityStateAsync<int>(entityId);
Use Cases
- Shopping carts
- Game state
- Rate limiting counters
- Aggregations
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.