I have created a .net 8 isolated function app as a POC for using durable entities containing a single entity. Also created 2 endpoints, one to retrieve the entity value, the other to act on the entity. When retrieving the value of the entity it is always null. I have left the app running overnight to see if it is a timing issue and the value is still returned as null. I have tried this both running on Azureite as well a storage account in Azure.
The entity function is recognized by the framework but a breakpoint inside the function is never hit.
The code below is scraped directly from the MS documentation on Durable Entities. here
Entity Definition:
public class Counter : TaskEntity<int>
{
readonly ILogger logger;
public Counter(ILogger<Counter> logger)
{
this.logger = logger;
}
public void Add(int amount)
{
this.State += amount;
}
public Task Reset()
{
this.State = 0;
return Task.CompletedTask;
}
public Task<int> Get()
{
return Task.FromResult(this.State);
}
// Delete is implicitly defined when defining an entity this way
[Function(nameof(Counter))]
public static Task Run([EntityTrigger] TaskEntityDispatcher dispatcher)
=> dispatcher.DispatchAsync<Counter>();
}
Function Definitions:
[Function("GetCounter")]
public static async Task<HttpResponseData> GetCounter(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "Counter/{entityKey}")] HttpRequestData req,
[DurableClient] DurableTaskClient client, string entityKey)
{
var entityId = new EntityInstanceId("Counter", entityKey);
EntityMetadata<int>? entity = await client.Entities.GetEntityAsync<int>(entityId);
HttpResponseData response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(entity?.State);
return response;
}
[Function("AddCounter")]
public static async Task<HttpResponseData> AddCounter(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "Counter/{entityKey}/add")] HttpRequestData req,
[DurableClient] DurableTaskClient client, string entityKey)
{
var entityId = new EntityInstanceId("Counter", entityKey);
await client.Entities.SignalEntityAsync(entityId, "add", 1);
HttpResponseData response = req.CreateResponse(HttpStatusCode.OK);
return response;
}