dotnet / dotnet/extensions

[API Proposal]: AutoActivation should support async initialization

Open
#5,045 3 comments 0 reactions 0 assignees View on GitHub
api-suggestion area-fundamentals
Dominant language
C#
Stars
3.2k
Forks
894
Avg merge
1d 12h
Merged PRs (30d)
23

Description

### 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

```csharp
namespace Microsoft.Extensions.DependencyInjection;

public interface IAsyncAutoActivation : IAsyncDisposable
{
Task OnActivationAsync();
}
```

### API Usage

```csharp
class MySingleton : IAsyncAutoActivation { .. }

services.AddActivatedSingleton();
```

### 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**.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.