extensions
extensions copied to clipboard
[API Proposal]: AutoActivation should support async initialization
Background and motivation
If you are using auto activation you would likely need some logic to run upon activation that could potentially require async code.
API Proposal
namespace Microsoft.Extensions.DependencyInjection;
public interface IAsyncAutoActivation : IAsyncDisposable
{
Task OnActivationAsync();
}
API Usage
class MySingleton : IAsyncAutoActivation { .. }
services.AddActivatedSingleton<MySingleton>();
Additional considerations
Async activations should not block each other, that is, they would run concurrently.
There's also the question of how to handle failed tasks which I think it should prevent the application from running.