Azure Durable Functions do not support Keyed Services
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
Hi all,
I am attempting to use keyed services in a .NET 8 project using azure durable functions. My startup in my azure functions project looks like this:
```
services.AddKeyedTransient("ExampleKey1", (serviceProvider, o) =>
{
var exampleClass = new ExampleClass();
exampleClass.UniqueString = "First Example String";
return exampleClass;
})
services.AddKeyedTransient("ExampleKey2", (serviceProvider, o) =>
{
var exampleClass = new ExampleClass();
exampleClass.UniqueString = "second Example String";
return exampleClass;
})
```
and my constructor for my orchestration Function looks like this:
```
private IExampleInterface _example1;
private IExampleInterface _example2;
Public ExampleOrchestrationFunction([FromKeyedServices("ExampleKey1")] IExampleInterface example1, [FromKeyedServices("ExampleKey2")] IExampleInterface example2)
{
_example1 = example1;
_example2 = example2;
}
```
When my function is triggered, I am receiving the following error:
"This service provider doesn't support keyed services."
I was wondering if azure functions currently do not support the .NET 8 keyed services, or if there is a work around to use them that someone has found, or if it's a bug?
I appreciate the help with this,
Dave.
Stack trace
```
Severity level: Error, Message: 6d6777a6-d51c-4b0d-af74-a0f2e4937484: Function 'RedactedOrchestration (Orchestrator)' failed with an error. Reason: System.InvalidOperationException: This service provider doesn't support keyed services.
at lambda_method1039(Closure, IServiceProvider, Object[])
at Microsoft.Azure.WebJobs.Host.Executors.DefaultJobActivator.CreateInstance[T](IServiceProvider serviceProvider) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\DefaultJobActivator.cs:line 37
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.CreateInstance(IFunctionInstanceEx functionInstance) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 44
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ParameterHelper.Initialize() in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 793
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance, CancellationToken cancellationToken) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 104
at Microsoft.Azure.WebJobs.Extensions.DurableTask.TaskOrchestrationShim.InvokeUserCodeAndHandleResults(RegisteredFunctionInfo orchestratorInfo, OrchestrationContext innerContext) in D:\a\_work\1\s\src\WebJobs.Extensions.DurableTask\Listener\TaskOrchestrationShim.cs:line 150. IsReplay: False. State: Failed. HubName: Redacted. AppName: . SlotName: . ExtensionVersion: 2.9.6. SequenceNumber: 22. TaskEventId: -1
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.