Skip to content

Commit

Permalink
Clean up modifiers and code
Browse files Browse the repository at this point in the history
  • Loading branch information
generik0 committed Dec 9, 2020
1 parent 1e1f6ef commit 6d8fb32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,40 @@ 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);
}
}

public object GetRequiredService(Type serviceType)
{
using(var fs = new ExtensionContainerScope.ForcedScope(scope))
using(var _ = new ExtensionContainerScope.ForcedScope(scope))
{
return ResolveInstanceOrNull(serviceType, false);
}
}

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)
{
Expand Down

0 comments on commit 6d8fb32

Please sign in to comment.