Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support keyed services dependency injection #2478

Closed
wilsjame opened this issue May 21, 2024 · 2 comments
Closed

Support keyed services dependency injection #2478

wilsjame opened this issue May 21, 2024 · 2 comments

Comments

@wilsjame
Copy link

wilsjame commented May 21, 2024

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.

@cjaliaga cjaliaga transferred this issue from Azure/azure-functions-host May 22, 2024
@jviau
Copy link
Contributor

jviau commented May 22, 2024

@wilsjame are you referencing Microsoft.Extensions.DependencyInjection/8.0.0?

@wilsjame
Copy link
Author

@wilsjame are you referencing Microsoft.Extensions.DependencyInjection/8.0.0?

Working now. Was not aware it was a transitive package and NuGet was installing 6.0.0 instead. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants