From a202ed58f7369bb1a91ddcc42bcfbf588fdfc11a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Al=C3=A9aume=20Muller?= Date: Fri, 20 Mar 2026 13:12:33 +0100 Subject: [PATCH] fix: change AddWorkflow default lifetime from Singleton to Transient --- .../HostApplicationBuilderWorkflowExtensions.cs | 2 +- .../HostApplicationBuilderWorkflowExtensionsTests.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderWorkflowExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderWorkflowExtensions.cs index cbefe94f1f..12be59052c 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderWorkflowExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderWorkflowExtensions.cs @@ -26,7 +26,7 @@ public static class HostApplicationBuilderWorkflowExtensions /// /// Thrown when the factory delegate returns null or a workflow with a name that doesn't match the expected name. /// - public static IHostedWorkflowBuilder AddWorkflow(this IHostApplicationBuilder builder, string name, Func createWorkflowDelegate, ServiceLifetime lifetime = ServiceLifetime.Singleton) + public static IHostedWorkflowBuilder AddWorkflow(this IHostApplicationBuilder builder, string name, Func createWorkflowDelegate, ServiceLifetime lifetime = ServiceLifetime.Transient) { Throw.IfNull(builder); Throw.IfNull(name); diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.UnitTests/HostApplicationBuilderWorkflowExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.UnitTests/HostApplicationBuilderWorkflowExtensionsTests.cs index 1c5649d17c..00d6ab7aa5 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.UnitTests/HostApplicationBuilderWorkflowExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.UnitTests/HostApplicationBuilderWorkflowExtensionsTests.cs @@ -63,10 +63,10 @@ public void AddWorkflow_ValidParameters_ReturnsBuilder() } /// - /// Verifies that AddWorkflow registers the workflow as a keyed singleton service by default. + /// Verifies that AddWorkflow registers the workflow as a keyed transient service by default. /// [Fact] - public void AddWorkflow_RegistersKeyedSingleton() + public void AddWorkflow_RegistersKeyedTransient() { var builder = new HostApplicationBuilder(); const string WorkflowName = "testWorkflow"; @@ -78,7 +78,7 @@ public void AddWorkflow_RegistersKeyedSingleton() d.ServiceType == typeof(Workflow)); Assert.NotNull(descriptor); - Assert.Equal(ServiceLifetime.Singleton, descriptor.Lifetime); + Assert.Equal(ServiceLifetime.Transient, descriptor.Lifetime); } ///