Skip to content

Commit

Permalink
Rename ExtensionContainerScope to Base
Browse files Browse the repository at this point in the history
  • Loading branch information
generik0 committed Dec 10, 2020
1 parent 32ce9c5 commit f6740c4
Showing 1 changed file with 12 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
// Copyright 2004-2020 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.Windsor.Extensions.DependencyInjection.Scope
{
using System;
Expand All @@ -21,44 +7,30 @@ namespace Castle.Windsor.Extensions.DependencyInjection.Scope
using Castle.MicroKernel;
using Castle.MicroKernel.Lifestyle.Scoped;

internal class ExtensionContainerScope : ILifetimeScope, IDisposable
internal abstract class ExtensionContainerScopeBase : ILifetimeScope, IDisposable
{

/// <summary>Current scope for the thread. Initial scope will be set when calling BeginRootScope from a ExtensionContainerRootScope instance.</summary>
/// <exception cref="InvalidOperationException">Thrown when there is no scope available.</exception>
internal static ExtensionContainerScope Current
{
get => current.Value ?? throw new InvalidOperationException("No scope available");
set => current.Value = value;
}
protected static readonly AsyncLocal<ExtensionContainerScope> current = new AsyncLocal<ExtensionContainerScope>();

protected static readonly AsyncLocal<ExtensionContainerScopeBase> current = new AsyncLocal<ExtensionContainerScopeBase>();
public static string TransientMarker = "Transient";
private readonly ExtensionContainerScope parent;
private readonly IScopeCache scopeCache;

protected ExtensionContainerScope(ExtensionContainerScope parent)
protected ExtensionContainerScopeBase()
{
scopeCache = new ScopeCache();
current.Value = this;
this.parent = parent;
RootScope = parent?.RootScope ?? this as ExtensionContainerRootScope;
}

internal ExtensionContainerRootScope RootScope { get; }

internal static ExtensionContainerScope BeginScope()
/// <summary>Current scope for the thread. Initial scope will be set when calling BeginRootScope from a ExtensionContainerRootScope instance.</summary>
/// <exception cref="InvalidOperationException">Thrown when there is no scope available.</exception>
internal static ExtensionContainerScopeBase Current
{
return new ExtensionContainerScope(Current);
get => current.Value ?? throw new InvalidOperationException("No scope available");
set => current.Value = value;
}

public void Dispose()
{
if (current.Value == this)
{
current.Value = parent;
}
internal virtual ExtensionContainerScopeBase RootScope { get; set; }

public virtual void Dispose()
{
if (scopeCache is IDisposable disposableCache)
{
disposableCache.Dispose();
Expand Down Expand Up @@ -88,4 +60,4 @@ public Burden GetCachedInstance(ComponentModel model, ScopedInstanceActivationCa
}
}
}
}
}

0 comments on commit f6740c4

Please sign in to comment.