diff --git a/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs b/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs index e15809ea50..01944ddd68 100644 --- a/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs +++ b/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs @@ -36,9 +36,9 @@ protected ExtensionContainerScope(ExtensionContainerScope parent, ExtensionConta this.parent = parent; } - public ExtensionContainerRootScope RootScope { get; } + internal ExtensionContainerRootScope RootScope { get; } - public static ExtensionContainerScope BeginScope() + internal static ExtensionContainerScope BeginScope() { var parent = Current; if (parent == null) throw new ArgumentNullException($"There is no parent scope to allow for BeginScope"); @@ -89,12 +89,12 @@ internal class ForcedScope : IDisposable private readonly ExtensionContainerScope previousScope; public ForcedScope(ExtensionContainerScope scope) { - previousScope = ExtensionContainerScope.Current; - ExtensionContainerScope.current.Value = scope; + previousScope = Current; + current.Value = scope; } public void Dispose() { - ExtensionContainerScope.current.Value = previousScope; + current.Value = previousScope; } } } diff --git a/src/Castle.Windsor.Extensions.DependencyInjection/WindsorScopedServiceProvider.cs b/src/Castle.Windsor.Extensions.DependencyInjection/WindsorScopedServiceProvider.cs index cbbc331b33..e561a13a95 100644 --- a/src/Castle.Windsor.Extensions.DependencyInjection/WindsorScopedServiceProvider.cs +++ b/src/Castle.Windsor.Extensions.DependencyInjection/WindsorScopedServiceProvider.cs @@ -27,19 +27,19 @@ namespace Castle.Windsor.Extensions.DependencyInjection internal class WindsorScopedServiceProvider : IServiceProvider, ISupportRequiredService, IDisposable { private readonly ExtensionContainerScope scope; - private bool disposing = false; + private bool disposing; private readonly IWindsorContainer container; public WindsorScopedServiceProvider(IWindsorContainer container) { this.container = container; - this.scope = ExtensionContainerScope.Current; + scope = ExtensionContainerScope.Current; } public object GetService(Type serviceType) { - using(var fs = new ExtensionContainerScope.ForcedScope(scope)) + using(var _ = new ExtensionContainerScope.ForcedScope(scope)) { return ResolveInstanceOrNull(serviceType, true); } @@ -47,7 +47,7 @@ public object GetService(Type serviceType) public object GetRequiredService(Type serviceType) { - using(var fs = new ExtensionContainerScope.ForcedScope(scope)) + using(var _ = new ExtensionContainerScope.ForcedScope(scope)) { return ResolveInstanceOrNull(serviceType, false); } @@ -55,20 +55,12 @@ public object GetRequiredService(Type serviceType) public void Dispose() { - if(scope is ExtensionContainerRootScope) - { - if(!disposing) - { - disposing = true; - var disposableScope = scope as IDisposable; - if(disposableScope != null) - { - disposableScope.Dispose(); - } - container.Dispose(); - } - - } + if (!(scope is ExtensionContainerRootScope)) return; + if (disposing) return; + disposing = true; + var disposableScope = scope as IDisposable; + disposableScope?.Dispose(); + container.Dispose(); } private object ResolveInstanceOrNull(Type serviceType, bool isOptional) {