From d3aecbf6be49cf1420af5d3b6126bb4f77e24c50 Mon Sep 17 00:00:00 2001 From: Rik Svendsen Rose Date: Mon, 7 Dec 2020 12:02:18 +0100 Subject: [PATCH] Change BeginScope to utilize the self contained current scope #563 --- .../Scope/ExtensionContainerScope.cs | 4 +++- .../WindsorScopeFactory.cs | 5 +---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs b/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs index ead6cec9ed..ce644beb58 100644 --- a/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs +++ b/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs @@ -42,8 +42,10 @@ protected ExtensionContainerScope( public ExtensionContainerRootScope RootScope => this as ExtensionContainerRootScope ?? rootScope; - public static ExtensionContainerScope BeginScope(ExtensionContainerScope parent, ExtensionContainerRootScope rootScope) + public static ExtensionContainerScope BeginScope() { + var parent = Current; + var rootScope = Current?.RootScope; if (rootScope == null) throw new ArgumentNullException(nameof(rootScope)); diff --git a/src/Castle.Windsor.Extensions.DependencyInjection/WindsorScopeFactory.cs b/src/Castle.Windsor.Extensions.DependencyInjection/WindsorScopeFactory.cs index 4264ff28fb..4e5ae8499a 100644 --- a/src/Castle.Windsor.Extensions.DependencyInjection/WindsorScopeFactory.cs +++ b/src/Castle.Windsor.Extensions.DependencyInjection/WindsorScopeFactory.cs @@ -38,10 +38,7 @@ public WindsorScopeFactory( public IServiceScope CreateScope() { var scope = - ExtensionContainerScope - .BeginScope( - ExtensionContainerScope.Current, - rootScope); + ExtensionContainerScope.BeginScope(); //since WindsorServiceProvider is scoped, this gives us new instance var provider = scopeFactoryContainer.Resolve();