Support keyed services dependency injection
wilsjame opened this issue · 3 comments
wilsjame commented
What problem would the feature you're requesting solve? Please describe.
Keyed services dependency injection was introduced in .NET 8. It appears to be unavailable when configuring services for Azure Functions. Including this feature would be great to have!
Describe the solution you'd like
Add support for keyed services dependency injection (AddKeyedSingleton
, AddKeyedScoped
, and AddKeyedTransient
).
For example, services.AddKeyedSingleton
would be available with the following project file and Program.cs
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
// Currently unavailable
services.AddKeyedSingleton<ICache, BigCache>("big")
services.AddKeyedSingleton<ICache, SmallCache>("small")
}
Describe alternatives you've considered
Injecting multiple instances of the same class and accessing them through an IEnumerable<>
. Implementing a factory pattern.