Skip to content

Commit 54f9303

Browse files
committed
Improving debugging
1 parent 5e685c7 commit 54f9303

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

package.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<Version>5.8.10</Version>
4+
<Version>5.8.11</Version>
55
<PackageReleaseNotes>This package is compatible with .NET Standard 1.0 and 2.0, .NET Core 1.0 and 2.0, .NET 4.0, 4.5, 4.6, 4.7</PackageReleaseNotes>
66
</PropertyGroup>
77

src/UnityContainer.Implementation.cs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Diagnostics.CodeAnalysis;
45
using System.Globalization;
56
using System.Linq;
67
using System.Reflection;
8+
using System.Text;
79
using Unity.Builder;
810
using Unity.Builder.Strategy;
911
using Unity.Container;
@@ -27,6 +29,7 @@
2729
namespace Unity
2830
{
2931
[CLSCompliant(true)]
32+
[DebuggerDisplay("{DebugName()}")]
3033
public partial class UnityContainer
3134
{
3235
#region Delegates
@@ -41,21 +44,21 @@ public partial class UnityContainer
4144
#region Fields
4245

4346
// Container specific
44-
private readonly UnityContainer _parent;
4547
internal readonly LifetimeContainer _lifetimeContainer;
4648
private List<UnityContainerExtension> _extensions;
47-
private UnityContainer _root;
49+
[DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly UnityContainer _parent;
50+
[DebuggerBrowsable(DebuggerBrowsableState.Never)] private UnityContainer _root;
4851

4952
// Policies
50-
private readonly ContainerContext _context;
53+
[DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly ContainerContext _context;
5154

5255
// 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;
5558

5659
// 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;
5962

6063
// Events
6164
private event EventHandler<RegisterEventArgs> Registering;
@@ -67,17 +70,17 @@ public partial class UnityContainer
6770
internal BuilderStrategy[] _buildChain;
6871

6972
// 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;
8184

8285
#endregion
8386

@@ -211,6 +214,18 @@ private IPolicySet GetDefaultPolicies()
211214

212215
#region Implementation
213216

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+
214229
private void CreateAndSetPolicy(Type type, string name, Type policyInterface, IBuilderPolicy policy)
215230
{
216231
lock (GetRegistration)

src/UnityContainer.Registration.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Globalization;
45
using System.Linq;
56
using System.Reflection;
@@ -17,8 +18,8 @@ public partial class UnityContainer
1718
{
1819
#region Constants
1920

20-
private const int ContainerInitialCapacity = 37;
21-
private const int ListToHashCutoverPoint = 8;
21+
[DebuggerBrowsable(DebuggerBrowsableState.Never)] private const int ContainerInitialCapacity = 37;
22+
[DebuggerBrowsable(DebuggerBrowsableState.Never)] private const int ListToHashCutoverPoint = 8;
2223

2324
#endregion
2425

src/UnityContainer.ServiceProvider.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)