1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Diagnostics ;
3
4
using System . Diagnostics . CodeAnalysis ;
4
5
using System . Globalization ;
5
6
using System . Linq ;
6
7
using System . Reflection ;
8
+ using System . Text ;
7
9
using Unity . Builder ;
8
10
using Unity . Builder . Strategy ;
9
11
using Unity . Container ;
27
29
namespace Unity
28
30
{
29
31
[ CLSCompliant ( true ) ]
32
+ [ DebuggerDisplay ( "{DebugName()}" ) ]
30
33
public partial class UnityContainer
31
34
{
32
35
#region Delegates
@@ -41,21 +44,21 @@ public partial class UnityContainer
41
44
#region Fields
42
45
43
46
// Container specific
44
- private readonly UnityContainer _parent ;
45
47
internal readonly LifetimeContainer _lifetimeContainer ;
46
48
private List < UnityContainerExtension > _extensions ;
47
- private UnityContainer _root ;
49
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private readonly UnityContainer _parent ;
50
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private UnityContainer _root ;
48
51
49
52
// Policies
50
- private readonly ContainerContext _context ;
53
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private readonly ContainerContext _context ;
51
54
52
55
// Strategies
53
- private StagedStrategyChain < BuilderStrategy , UnityBuildStage > _strategies ;
54
- private StagedStrategyChain < BuilderStrategy , BuilderStage > _buildPlanStrategies ;
56
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private StagedStrategyChain < BuilderStrategy , UnityBuildStage > _strategies ;
57
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private StagedStrategyChain < BuilderStrategy , BuilderStage > _buildPlanStrategies ;
55
58
56
59
// Registrations
57
- private readonly object _syncRoot = new object ( ) ;
58
- private HashRegistry < Type , IRegistry < string , IPolicySet > > _registrations ;
60
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private readonly object _syncRoot = new object ( ) ;
61
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private HashRegistry < Type , IRegistry < string , IPolicySet > > _registrations ;
59
62
60
63
// Events
61
64
private event EventHandler < RegisterEventArgs > Registering ;
@@ -67,17 +70,17 @@ public partial class UnityContainer
67
70
internal BuilderStrategy [ ] _buildChain ;
68
71
69
72
// Methods
70
- internal Func < Type , string , IPolicySet > GetRegistration ;
71
- internal Func < IBuilderContext , object > BuildUpPipeline ;
72
- internal Func < INamedType , IPolicySet > Register ;
73
- internal GetPolicyDelegate GetPolicy ;
74
- internal SetPolicyDelegate SetPolicy ;
75
- internal ClearPolicyDelegate ClearPolicy ;
76
-
77
- private Func < Type , string , IPolicySet > _get ;
78
- private Func < Type , string , Type , IPolicySet > _getGenericRegistration ;
79
- private Func < Type , bool > _isTypeExplicitlyRegistered ;
80
- private Func < Type , string , bool > _isExplicitlyRegistered ;
73
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] internal Func < Type , string , IPolicySet > GetRegistration ;
74
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] internal Func < IBuilderContext , object > BuildUpPipeline ;
75
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] internal Func < INamedType , IPolicySet > Register ;
76
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] internal GetPolicyDelegate GetPolicy ;
77
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] internal SetPolicyDelegate SetPolicy ;
78
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] internal ClearPolicyDelegate ClearPolicy ;
79
+
80
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private Func < Type , string , IPolicySet > _get ;
81
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private Func < Type , string , Type , IPolicySet > _getGenericRegistration ;
82
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private Func < Type , bool > _isTypeExplicitlyRegistered ;
83
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ] private Func < Type , string , bool > _isExplicitlyRegistered ;
81
84
82
85
#endregion
83
86
@@ -211,6 +214,18 @@ private IPolicySet GetDefaultPolicies()
211
214
212
215
#region Implementation
213
216
217
+ private string DebugName ( )
218
+ {
219
+ var types = ( _registrations ? . Keys ?? Enumerable . Empty < Type > ( ) )
220
+ . SelectMany ( t => _registrations [ t ] . Values )
221
+ . OfType < IContainerRegistration > ( )
222
+ . Count ( ) ;
223
+
224
+ if ( null == _parent ) return $ "Container[{ types } ]";
225
+
226
+ return _parent . DebugName ( ) + $ ".Child[{ types } ]"; ;
227
+ }
228
+
214
229
private void CreateAndSetPolicy ( Type type , string name , Type policyInterface , IBuilderPolicy policy )
215
230
{
216
231
lock ( GetRegistration )
0 commit comments