extensions icon indicating copy to clipboard operation
extensions copied to clipboard

[API Proposal]: AutoActivation should support async initialization

Open alrz opened this issue 1 year ago • 2 comments

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.

alrz avatar Mar 14 '24 10:03 alrz