Would love to see class based Durable Entities work with the built-in dependency injection support for Functions. Looks like it was mentioned in #763, I don鈥檛 think the feature was enabled.
I鈥檓 guessing the programming model would look similar to how DI works with non-Durable Functions today.
public class Counter
{
[JsonProperty("value")]
public int CurrentValue { get; set; }
public int Get() => this.CurrentValue;
private ILogger _logger;
private IMyService _service;
public Counter(ILogger logger, IMyService service) {
_logger = logger;
_service = service;
}
[FunctionName(nameof(Counter))]
public static Task Run([EntityTrigger] IDurableEntityContext ctx)
=> ctx.DispatchAsync<Counter>();
}
@ConnorMcMahon I think this would be a good one for you to investigate. I think it's going to be really important to enable something like this in order for Durable Entities to become viable for production applications. There might be two angles to consider:
ctx.DispatchAsync<ICounter>() and then get the implementation of ICounter from DI? I haven't figured out exactly what scenarios this would enable, so it might be worth considering possible use-cases first.Fabio might be able to provide some guidance on how we can achieve this, if necessary.
This has been merged and will be part of the v2.0.0-beta2 release.
Most helpful comment
This has been merged and will be part of the v2.0.0-beta2 release.