@@ -6,7 +6,9 @@ namespace SimpleInjector
66 using System ;
77 using System . Collections ;
88 using System . Collections . Generic ;
9+ using System . Diagnostics ;
910 using System . Runtime . CompilerServices ;
11+ using System . Threading ;
1012 using System . Threading . Tasks ;
1113 using SimpleInjector . Advanced ;
1214 using SimpleInjector . Internals ;
@@ -52,12 +54,16 @@ public partial class Scope
5254 /// thread-safe methods. This means that once the Scope is ready for disposal, only a single thread should
5355 /// access it. Also note that although the scope is thread safe, cached instances might not be.
5456 /// </remarks>
57+ [ DebuggerDisplay ( "{DebugString,nq}" ) ]
5558 public partial class Scope : ApiObject , IDisposable , IServiceProvider
5659 {
5760 private const int MaximumDisposeRecursion = 100 ;
5861
62+ private static long counter = 0 ;
63+
5964 private readonly object syncRoot = new ( ) ;
6065 private readonly ScopeManager ? manager ;
66+ private readonly long scopeId = Interlocked . Increment ( ref counter ) ;
6167
6268 private IDictionary ? items ;
6369 private Dictionary < Registration , object > ? cachedInstances ;
@@ -109,6 +115,11 @@ private enum DisposeState
109115
110116 internal bool IsContainerScope { get ; set ; }
111117
118+ private string DebugString =>
119+ "Scope #" + this . scopeId
120+ + ( this . ParentScope is not null ? ( " for Parent #" + this . ParentScope . scopeId ) : "" )
121+ + ( this . Container is not null ? ( " for Container #" + this . Container ! . ContainerId ) : "" ) ;
122+
112123 /// <summary>Gets an instance of the given <typeparamref name="TService"/> for the current scope.</summary>
113124 /// <typeparam name="TService">The type of the service to resolve.</typeparam>
114125 /// <remarks><b>Thread safety:</b> Calls to this method are thread safe.</remarks>
0 commit comments