microsoft / microsoft/aspire

Support asyncronous connection creation in DI

Open
#12,988 7 comments 0 reactions 0 assignees View on GitHub
area-integrations redis
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Currently Aspire is putting long lived connection objects in DI as singletons, like `ConnectionMultiplexer` for Redis. This ultimately forces the app to establish the connection(s) before the app can start its own bootstrapping logic, delaying the time before it can serve its first response.

This was discussed in #565.

### Describe the solution you'd like

I would like to request that Aspire registers a shim that can lazily establish the connection when asked for. It could be as simple as `Task` or an interface that contains method along the lines of `ValueTask GetAsync()`.

This is the first suggestion of #565.

### Additional context

We have observed that registering a shim and egarly establishing the connection in parallel to the app startup reduces the time of first response by about two seconds.

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.