Родитель
3db3623c8e
Коммит
0428d6fd0e
|
@ -17,7 +17,7 @@ namespace Unity
|
|||
Debug.Assert(null != Container._root._registry);
|
||||
|
||||
var registry = Container._root._registry;
|
||||
return registry.Entries[0].Value.Get(policyInterface);
|
||||
return registry.Entries[0].Policies.Get(policyInterface);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -36,9 +36,9 @@ namespace Unity
|
|||
for (var i = registry.Buckets[targetBucket]; i >= 0; i = registry.Entries[i].Next)
|
||||
{
|
||||
ref var entry = ref registry.Entries[i];
|
||||
if (entry.Key != key || entry.Value is ImplicitRegistration) continue;
|
||||
if (entry.Key != key || entry.Policies is ImplicitRegistration) continue;
|
||||
|
||||
return entry.Value.Get(policyInterface);
|
||||
return entry.Policies.Get(policyInterface);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ namespace Unity
|
|||
ref var entry = ref registry.Entries[i];
|
||||
if (entry.Key != key) continue;
|
||||
|
||||
return entry.Value.Get(policyInterface);
|
||||
return entry.Policies.Get(policyInterface);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ namespace Unity
|
|||
Debug.Assert(null != Container._root._registry);
|
||||
|
||||
var registry = Container._root._registry;
|
||||
registry.Entries[0].Value.Set(policyInterface, policy);
|
||||
registry.Entries[0].Policies.Set(policyInterface, policy);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -85,26 +85,26 @@ namespace Unity
|
|||
{
|
||||
var key = new HashKey(type);
|
||||
|
||||
lock (Container._syncRegistry)
|
||||
lock (Container._syncLock)
|
||||
{
|
||||
if (null == Container._registry) Container._registry = new Registry<IPolicySet>();
|
||||
if (null == Container._registry) Container._registry = new Registry();
|
||||
|
||||
// Check for the existing
|
||||
var targetBucket = key.HashCode % Container._registry.Buckets.Length;
|
||||
for (var i = Container._registry.Buckets[targetBucket]; i >= 0; i = Container._registry.Entries[i].Next)
|
||||
{
|
||||
ref var candidate = ref Container._registry.Entries[i];
|
||||
if (candidate.Key != key || candidate.Value is ImplicitRegistration)
|
||||
if (candidate.Key != key || candidate.Policies is ImplicitRegistration)
|
||||
continue;
|
||||
|
||||
candidate.Value.Set(policyInterface, policy);
|
||||
candidate.Policies.Set(policyInterface, policy);
|
||||
return;
|
||||
}
|
||||
|
||||
// Expand only if no more space
|
||||
if (Container._registry.Count >= Container._registry.Entries.Length)
|
||||
{
|
||||
Container._registry = new Registry<IPolicySet>(Container._registry);
|
||||
Container._registry = new Registry(Container._registry);
|
||||
targetBucket = key.HashCode % Container._registry.Buckets.Length;
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ namespace Unity
|
|||
entry.Key = key;
|
||||
entry.Type = type;
|
||||
entry.Next = Container._registry.Buckets[targetBucket];
|
||||
entry.Value = new PolicySet(Container, policyInterface, policy);
|
||||
entry.Policies = new PolicySet(Container, policyInterface, policy);
|
||||
Container._registry.Buckets[targetBucket] = Container._registry.Count++;
|
||||
}
|
||||
}
|
||||
|
@ -123,9 +123,9 @@ namespace Unity
|
|||
{
|
||||
var key = new HashKey(type, name);
|
||||
|
||||
lock (Container._syncRegistry)
|
||||
lock (Container._syncLock)
|
||||
{
|
||||
if (null == Container._registry) Container._registry = new Registry<IPolicySet>();
|
||||
if (null == Container._registry) Container._registry = new Registry();
|
||||
|
||||
var targetBucket = key.HashCode % Container._registry.Buckets.Length;
|
||||
|
||||
|
@ -135,14 +135,14 @@ namespace Unity
|
|||
ref var candidate = ref Container._registry.Entries[i];
|
||||
if (candidate.Key != key) continue;
|
||||
|
||||
candidate.Value.Set(policyInterface, policy);
|
||||
candidate.Policies.Set(policyInterface, policy);
|
||||
return;
|
||||
}
|
||||
|
||||
// Expand only if no more space
|
||||
if (Container._registry.Count >= Container._registry.Entries.Length)
|
||||
{
|
||||
Container._registry = new Registry<IPolicySet>(Container._registry);
|
||||
Container._registry = new Registry(Container._registry);
|
||||
targetBucket = key.HashCode % Container._registry.Buckets.Length;
|
||||
}
|
||||
|
||||
|
@ -151,8 +151,8 @@ namespace Unity
|
|||
entry.Key = key;
|
||||
entry.Type = type;
|
||||
entry.Next = Container._registry.Buckets[targetBucket];
|
||||
entry.Value = new ImplicitRegistration(Container, name);
|
||||
entry.Value.Set(policyInterface, policy);
|
||||
entry.Policies = new ImplicitRegistration(Container, name);
|
||||
entry.Policies.Set(policyInterface, policy);
|
||||
Container._registry.Buckets[targetBucket] = Container._registry.Count++;
|
||||
}
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ namespace Unity
|
|||
ref var entry = ref registry.Entries[i];
|
||||
if (entry.Key != key) continue;
|
||||
|
||||
entry.Value.Clear(policyInterface);
|
||||
entry.Policies.Clear(policyInterface);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Unity.Lifetime;
|
||||
using Unity.Policy;
|
||||
|
||||
namespace Unity.Registration
|
||||
{
|
||||
|
@ -9,10 +10,10 @@ namespace Unity.Registration
|
|||
{
|
||||
private readonly ExplicitRegistration _registration;
|
||||
|
||||
public ContainerRegistration(Type type, ExplicitRegistration registration)
|
||||
public ContainerRegistration(Type type, IPolicySet registration)
|
||||
{
|
||||
RegisteredType = type;
|
||||
_registration = registration;
|
||||
_registration = (ExplicitRegistration)registration;
|
||||
}
|
||||
|
||||
public Type RegisteredType { get; }
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Unity.Storage
|
|||
#region Fields
|
||||
|
||||
public readonly int HashCode;
|
||||
public readonly Type Type;
|
||||
private readonly int _type;
|
||||
private readonly int _name;
|
||||
|
||||
#endregion
|
||||
|
@ -18,30 +18,30 @@ namespace Unity.Storage
|
|||
|
||||
public HashKey(int _ = 0)
|
||||
{
|
||||
_type = 0;
|
||||
_name = 0;
|
||||
HashCode = 0;
|
||||
Type = typeof(NoType);
|
||||
}
|
||||
|
||||
public HashKey(Type type)
|
||||
{
|
||||
_type = type?.GetHashCode() ?? 0;
|
||||
_name = -1;
|
||||
HashCode = NamedType.GetHashCode(type?.GetHashCode() ?? 0, _name) & UnityContainer.HashMask;
|
||||
Type = type;
|
||||
HashCode = NamedType.GetHashCode(_type, _name) & UnityContainer.HashMask;
|
||||
}
|
||||
|
||||
public HashKey(string? name)
|
||||
{
|
||||
_type = name?.Length ?? 0;
|
||||
_name = name?.GetHashCode() ?? 0;
|
||||
HashCode = NamedType.GetHashCode(typeof(NoType), name) & UnityContainer.HashMask;
|
||||
Type = typeof(NoType);
|
||||
HashCode = NamedType.GetHashCode(_type, _name) & UnityContainer.HashMask;
|
||||
}
|
||||
|
||||
public HashKey(Type type, string? name)
|
||||
{
|
||||
_type = type?.GetHashCode() ?? 0;
|
||||
_name = name?.GetHashCode() ?? 0;
|
||||
HashCode = NamedType.GetHashCode(type, name) & UnityContainer.HashMask;
|
||||
Type = type;
|
||||
HashCode = NamedType.GetHashCode(_type, _name) & UnityContainer.HashMask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -63,7 +63,7 @@ namespace Unity.Storage
|
|||
public bool Equals(HashKey other)
|
||||
{
|
||||
return other.HashCode == HashCode &&
|
||||
other.Type == Type &&
|
||||
other._type == _type &&
|
||||
other._name == _name;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ namespace Unity.Storage
|
|||
{
|
||||
return obj is HashKey other &&
|
||||
other.HashCode == HashCode &&
|
||||
other.Type == Type &&
|
||||
other._type == _type &&
|
||||
other._name == _name;
|
||||
}
|
||||
|
||||
|
@ -80,24 +80,16 @@ namespace Unity.Storage
|
|||
public static bool operator ==(HashKey x, HashKey y)
|
||||
{
|
||||
return x.HashCode == y.HashCode &&
|
||||
x.Type == y.Type &&
|
||||
x._type == y._type &&
|
||||
x._name == y._name;
|
||||
}
|
||||
|
||||
public static bool operator !=(HashKey x, HashKey y)
|
||||
{
|
||||
return x.HashCode != y.HashCode ||
|
||||
x.Type != y.Type ||
|
||||
x._type != y._type ||
|
||||
x._name != y._name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region NoType
|
||||
|
||||
private class NoType { }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace Unity.Storage
|
|||
Array.Copy(metadata.Entries, 0, Entries, 0, metadata.Count);
|
||||
for (var i = 0; i < metadata.Count; i++)
|
||||
{
|
||||
var hashCode = Entries[i].HashCode.HashCode;
|
||||
var hashCode = Entries[i].HashKey.HashCode;
|
||||
if (hashCode < 0) continue;
|
||||
|
||||
var bucket = hashCode % Buckets.Length;
|
||||
|
@ -91,14 +91,14 @@ namespace Unity.Storage
|
|||
|
||||
#region Public Members
|
||||
|
||||
public int GetEntries(ref HashKey key, out int[]? data)
|
||||
public int GetMeta(ref HashKey key, out int[]? data)
|
||||
{
|
||||
var targetBucket = key.HashCode % Buckets.Length;
|
||||
|
||||
// Check if metadata exists
|
||||
for (var i = Buckets[targetBucket]; i >= 0; i = Entries[i].Next)
|
||||
{
|
||||
if (Entries[i].HashCode != key) continue;
|
||||
if (Entries[i].HashKey != key) continue;
|
||||
|
||||
// Get a fix on the buffer
|
||||
data = Entries[i].Value;
|
||||
|
@ -120,7 +120,7 @@ namespace Unity.Storage
|
|||
[DebuggerDisplay("{Value}", Name = "{Key}")]
|
||||
public struct Entry
|
||||
{
|
||||
public HashKey HashCode;
|
||||
public HashKey HashKey;
|
||||
public int Next;
|
||||
public Type Type;
|
||||
public int[] Value;
|
||||
|
|
|
@ -43,7 +43,9 @@ namespace Unity.Storage
|
|||
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
#pragma warning disable CS8603 // Possible null reference return.
|
||||
public IContainerRegistration Current => _current;
|
||||
#pragma warning restore CS8603 // Possible null reference return.
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Security;
|
||||
using Unity.Policy;
|
||||
|
||||
namespace Unity.Storage
|
||||
{
|
||||
[SecuritySafeCritical]
|
||||
public class Registry<TValue>
|
||||
public class Registry
|
||||
{
|
||||
#region Fields
|
||||
|
||||
|
@ -70,7 +71,7 @@ namespace Unity.Storage
|
|||
#endif
|
||||
}
|
||||
|
||||
public Registry(Registry<TValue> registry)
|
||||
public Registry(Registry registry)
|
||||
: this(registry._prime + 1)
|
||||
{
|
||||
Array.Copy(registry.Entries, 0, Entries, 0, registry.Count);
|
||||
|
@ -86,12 +87,12 @@ namespace Unity.Storage
|
|||
Count = registry.Count;
|
||||
}
|
||||
|
||||
public Registry(TValue value)
|
||||
public Registry(IPolicySet value)
|
||||
: this(0)
|
||||
{
|
||||
ref var entry = ref Entries[0];
|
||||
entry.Next = -1;
|
||||
entry.Value = value;
|
||||
entry.Policies = value;
|
||||
|
||||
Buckets[0] = 0;
|
||||
Count++;
|
||||
|
@ -115,7 +116,9 @@ namespace Unity.Storage
|
|||
public HashKey Key;
|
||||
public int Next;
|
||||
public Type Type;
|
||||
public TValue Value;
|
||||
public bool IsExplicit;
|
||||
public IPolicySet Policies;
|
||||
public IContainerRegistration Registration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Unity
|
|||
internal static readonly ResolveDelegate<BuilderContext> DefaultResolver = (ref BuilderContext c) => c.Existing;
|
||||
private static readonly TypeInfo DelegateType = typeof(Delegate).GetTypeInfo();
|
||||
internal const int HashMask = unchecked((int)(uint.MaxValue >> 1));
|
||||
private readonly object _syncRegistry = new object();
|
||||
private readonly object _syncLock = new object();
|
||||
private readonly object _syncMetadata = new object();
|
||||
private const int CollisionsCutPoint = 5;
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace Unity
|
|||
|
||||
// Essentials
|
||||
private Metadata? _metadata;
|
||||
private Registry<IPolicySet>? _registry;
|
||||
private Registry? _registry;
|
||||
private readonly UnityContainer _root;
|
||||
private readonly UnityContainer? _parent;
|
||||
|
||||
|
@ -57,7 +57,7 @@ namespace Unity
|
|||
private event EventHandler<ChildContainerCreatedEventArgs> ChildContainerCreated;
|
||||
|
||||
// Dynamic Members
|
||||
private Func<Type, string?, ImplicitRegistration, ImplicitRegistration?> Register;
|
||||
private Func<Type, string?, ExplicitRegistration, ExplicitRegistration?> Register;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace Unity
|
|||
|
||||
// Create Registry
|
||||
_metadata = new Metadata();
|
||||
_registry = new Registry<IPolicySet>(Defaults);
|
||||
_registry = new Registry(Defaults);
|
||||
_registry.Set(typeof(IUnityContainer), null, container);
|
||||
_registry.Set(typeof(IUnityContainerAsync), null, container);
|
||||
|
||||
|
@ -180,7 +180,7 @@ namespace Unity
|
|||
for (var i = registry.Buckets[targetBucket]; i >= 0; i = registry.Entries[i].Next)
|
||||
{
|
||||
ref var candidate = ref registry.Entries[i];
|
||||
if (candidate.Key != key) continue;
|
||||
if (candidate.Key != key || !candidate.IsExplicit) continue;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -202,8 +202,8 @@ namespace Unity
|
|||
set.Add(ref _root._registry.Entries[2].Key);
|
||||
|
||||
// IUnityContainer & IUnityContainerAsync
|
||||
yield return new ContainerRegistration(typeof(IUnityContainer), (ExplicitRegistration)_root._registry.Entries[1].Value);
|
||||
yield return new ContainerRegistration(typeof(IUnityContainerAsync), (ExplicitRegistration)_root._registry.Entries[2].Value);
|
||||
yield return _root._registry.Entries[1].Registration;
|
||||
yield return _root._registry.Entries[2].Registration;
|
||||
|
||||
// Explicit registrations
|
||||
for (UnityContainer? container = this; null != container; container = container._parent)
|
||||
|
@ -216,11 +216,13 @@ namespace Unity
|
|||
var registry = container._registry;
|
||||
for (var i = 0; i < registry.Count; i++)
|
||||
{
|
||||
if (!(registry.Entries[i].Value is ExplicitRegistration registration) ||
|
||||
!set.Add(ref registry.Entries[i].Key))
|
||||
if (!registry.Entries[i].IsExplicit || !set.Add(ref registry.Entries[i].Key))
|
||||
continue;
|
||||
|
||||
yield return new ContainerRegistration(registry.Entries[i].Type, registration);
|
||||
if (null == registry.Entries[i].Registration)
|
||||
registry.Entries[i].Registration = new ContainerRegistration(registry.Entries[i].Type, registry.Entries[i].Policies);
|
||||
|
||||
yield return registry.Entries[i].Registration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace Unity
|
|||
|
||||
for (var i = metadata.Buckets[targetBucket]; i >= 0; i = metadata.Entries[i].Next)
|
||||
{
|
||||
if (metadata.Entries[i].HashCode != key) continue;
|
||||
if (metadata.Entries[i].HashKey != key) continue;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -72,10 +72,10 @@ namespace Unity
|
|||
if (candidate.Key != key) continue;
|
||||
|
||||
// Found a registration
|
||||
if (!(candidate.Value is ImplicitRegistration))
|
||||
candidate.Value = container.CreateRegistration(type, name, candidate.Value);
|
||||
if (!(candidate.Policies is ImplicitRegistration))
|
||||
candidate.Policies = container.CreateRegistration(type, name, candidate.Policies);
|
||||
|
||||
return (ImplicitRegistration)candidate.Value;
|
||||
return (ImplicitRegistration)candidate.Policies;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,10 +115,10 @@ namespace Unity
|
|||
if (candidate.Key != keyExact) continue;
|
||||
|
||||
// Found a registration
|
||||
if (!(candidate.Value is ImplicitRegistration))
|
||||
candidate.Value = container.CreateRegistration(type, name, candidate.Value);
|
||||
if (!(candidate.Policies is ImplicitRegistration))
|
||||
candidate.Policies = container.CreateRegistration(type, name, candidate.Policies);
|
||||
|
||||
return (ImplicitRegistration)candidate.Value;
|
||||
return (ImplicitRegistration)candidate.Policies;
|
||||
}
|
||||
|
||||
// Generic registrations
|
||||
|
@ -144,7 +144,7 @@ namespace Unity
|
|||
continue;
|
||||
|
||||
// Found a factory
|
||||
return container.GetOrAdd(ref keyExact, type, name, candidate.Value);
|
||||
return container.GetOrAdd(ref keyExact, type, name, candidate.Policies);
|
||||
}
|
||||
|
||||
// Check for default factory
|
||||
|
@ -156,7 +156,7 @@ namespace Unity
|
|||
continue;
|
||||
|
||||
// Found a factory
|
||||
return container.GetOrAdd(ref keyExact, type, name, candidate.Value);
|
||||
return container.GetOrAdd(ref keyExact, type, name, candidate.Policies);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,11 +170,11 @@ namespace Unity
|
|||
|
||||
#region Registration manipulation
|
||||
|
||||
private ImplicitRegistration? InitAndAdd(Type type, string? name, ImplicitRegistration registration)
|
||||
private ExplicitRegistration? InitAndAdd(Type type, string? name, ExplicitRegistration registration)
|
||||
{
|
||||
lock (_syncRegistry)
|
||||
lock (_syncLock)
|
||||
{
|
||||
if (null == _registry) _registry = new Registry<IPolicySet>();
|
||||
if (null == _registry) _registry = new Registry();
|
||||
if (null == _metadata)
|
||||
{
|
||||
_metadata = new Metadata();
|
||||
|
@ -186,12 +186,11 @@ namespace Unity
|
|||
return Register(type, name, registration);
|
||||
}
|
||||
|
||||
private ImplicitRegistration? AddOrReplace(Type type, string? name, ImplicitRegistration registration)
|
||||
private ExplicitRegistration? AddOrReplace(Type type, string? name, ExplicitRegistration registration)
|
||||
{
|
||||
int position = -1;
|
||||
var collisions = 0;
|
||||
var key = new HashKey(type, name);
|
||||
var meta = new HashKey(type);
|
||||
var metaKey = new HashKey(type);
|
||||
|
||||
Debug.Assert(null != _registry);
|
||||
Debug.Assert(null != _metadata);
|
||||
|
@ -199,7 +198,7 @@ namespace Unity
|
|||
registration.AddRef();
|
||||
|
||||
// Registry
|
||||
lock (_syncRegistry)
|
||||
lock (_syncLock)
|
||||
{
|
||||
var targetBucket = key.HashCode % _registry.Buckets.Length;
|
||||
for (var i = _registry.Buckets[targetBucket]; i >= 0; i = _registry.Entries[i].Next)
|
||||
|
@ -212,10 +211,14 @@ namespace Unity
|
|||
}
|
||||
|
||||
// Swap the registration
|
||||
var existing = candidate.Value as ImplicitRegistration;
|
||||
var existing = candidate.Policies as ExplicitRegistration;
|
||||
|
||||
if (null == existing) registration.Add(candidate.Value);
|
||||
candidate.Value = registration;
|
||||
if (null == existing)
|
||||
{
|
||||
candidate.IsExplicit = true;
|
||||
registration.Add(candidate.Policies);
|
||||
}
|
||||
candidate.Policies = registration;
|
||||
|
||||
// Replaced registration
|
||||
return existing;
|
||||
|
@ -224,7 +227,7 @@ namespace Unity
|
|||
// Expand if required
|
||||
if (_registry.RequireToGrow || CollisionsCutPoint < collisions)
|
||||
{
|
||||
_registry = new Registry<IPolicySet>(_registry);
|
||||
_registry = new Registry(_registry);
|
||||
targetBucket = key.HashCode % _registry.Buckets.Length;
|
||||
}
|
||||
|
||||
|
@ -233,19 +236,20 @@ namespace Unity
|
|||
entry.Key = key;
|
||||
entry.Next = _registry.Buckets[targetBucket];
|
||||
entry.Type = type;
|
||||
entry.Value = registration;
|
||||
position = _registry.Count++;
|
||||
entry.IsExplicit = true;
|
||||
entry.Policies = registration;
|
||||
int position = _registry.Count++;
|
||||
_registry.Buckets[targetBucket] = position;
|
||||
|
||||
collisions = 0;
|
||||
|
||||
// Metadata
|
||||
targetBucket = meta.HashCode % _metadata.Buckets.Length;
|
||||
targetBucket = metaKey.HashCode % _metadata.Buckets.Length;
|
||||
|
||||
for (var i = _metadata.Buckets[targetBucket]; i >= 0; i = _metadata.Entries[i].Next)
|
||||
{
|
||||
ref var candidate = ref _metadata.Entries[i];
|
||||
if (candidate.HashCode != meta || candidate.Type != type)
|
||||
if (candidate.HashKey != metaKey || candidate.Type != type)
|
||||
{
|
||||
collisions++;
|
||||
continue;
|
||||
|
@ -270,13 +274,13 @@ namespace Unity
|
|||
if (_metadata.RequireToGrow || CollisionsCutPoint < collisions)
|
||||
{
|
||||
_metadata = new Metadata(_metadata);
|
||||
targetBucket = meta.HashCode % _metadata.Buckets.Length;
|
||||
targetBucket = metaKey.HashCode % _metadata.Buckets.Length;
|
||||
}
|
||||
|
||||
// Create new metadata entry
|
||||
ref var metadata = ref _metadata.Entries[_metadata.Count];
|
||||
metadata.Next = _metadata.Buckets[targetBucket];
|
||||
metadata.HashCode = meta;
|
||||
metadata.HashKey = metaKey;
|
||||
metadata.Type = type;
|
||||
metadata.Value = new int[] { 2, position };
|
||||
_metadata.Buckets[targetBucket] = _metadata.Count++;
|
||||
|
@ -296,7 +300,7 @@ namespace Unity
|
|||
{
|
||||
Debug.Assert(null != _registry);
|
||||
|
||||
lock (_syncRegistry)
|
||||
lock (_syncLock)
|
||||
{
|
||||
var collisions = 0;
|
||||
var targetBucket = key.HashCode % _registry.Buckets.Length;
|
||||
|
@ -311,16 +315,16 @@ namespace Unity
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!(candidate.Value is ImplicitRegistration))
|
||||
candidate.Value = CreateRegistration(type, name, candidate.Value);
|
||||
if (!(candidate.Policies is ImplicitRegistration))
|
||||
candidate.Policies = CreateRegistration(type, name, candidate.Policies);
|
||||
|
||||
return (ImplicitRegistration)candidate.Value;
|
||||
return (ImplicitRegistration)candidate.Policies;
|
||||
}
|
||||
|
||||
// Expand if required
|
||||
if (_registry.RequireToGrow || CollisionsCutPoint < collisions)
|
||||
{
|
||||
_registry = new Registry<IPolicySet>(_registry);
|
||||
_registry = new Registry(_registry);
|
||||
targetBucket = key.HashCode % _registry.Buckets.Length;
|
||||
}
|
||||
|
||||
|
@ -331,10 +335,10 @@ namespace Unity
|
|||
entry.Key = key;
|
||||
entry.Type = type;
|
||||
entry.Next = _registry.Buckets[targetBucket];
|
||||
entry.Value = registration;
|
||||
entry.Policies = registration;
|
||||
_registry.Buckets[targetBucket] = _registry.Count++;
|
||||
|
||||
return (ImplicitRegistration)entry.Value;
|
||||
return (ImplicitRegistration)entry.Policies;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -93,13 +93,13 @@ namespace Unity
|
|||
var registry = container._registry;
|
||||
|
||||
// Get indexes and iterate over them
|
||||
var length = container._metadata.GetEntries(ref key, out int[]? data);
|
||||
var length = container._metadata.GetMeta(ref key, out int[]? data);
|
||||
if (null != data && null != registry)
|
||||
{
|
||||
for (var i = 1; i < length; i++)
|
||||
{
|
||||
var index = data[i];
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Value;
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Policies;
|
||||
|
||||
if (!set.Add(registration.Name)) continue;
|
||||
|
||||
|
@ -153,13 +153,13 @@ namespace Unity
|
|||
var registry = container._registry;
|
||||
|
||||
// Get indexes for bound types and iterate over them
|
||||
var length = container._metadata.GetEntries(ref key, out int[]? data);
|
||||
var length = container._metadata.GetMeta(ref key, out int[]? data);
|
||||
if (null != data)
|
||||
{
|
||||
for (var i = 1; i < length; i++)
|
||||
{
|
||||
var index = data[i];
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Value;
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Policies;
|
||||
|
||||
if (!set.Add(registration.Name)) continue;
|
||||
|
||||
|
@ -177,13 +177,13 @@ namespace Unity
|
|||
}
|
||||
|
||||
// Get indexes for unbound types and iterate over them
|
||||
length = container._metadata.GetEntries(ref keyGeneric, out data);
|
||||
length = container._metadata.GetMeta(ref keyGeneric, out data);
|
||||
if (null != data)
|
||||
{
|
||||
for (var i = 1; i < length; i++)
|
||||
{
|
||||
var index = data[i];
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Value;
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Policies;
|
||||
|
||||
if (set.Add(registration.Name))
|
||||
{
|
||||
|
@ -270,13 +270,13 @@ namespace Unity
|
|||
var registry = container._registry;
|
||||
|
||||
// Get indexes and iterate over them
|
||||
var length = container._metadata.GetEntries(ref key, out int[]? data);
|
||||
var length = container._metadata.GetMeta(ref key, out int[]? data);
|
||||
if (null != data)
|
||||
{
|
||||
for (var i = 1; i < length; i++)
|
||||
{
|
||||
var index = data[i];
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Value;
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Policies;
|
||||
|
||||
if (null != registration.Name && set.Add(registration.Name))
|
||||
{
|
||||
|
@ -315,13 +315,13 @@ namespace Unity
|
|||
var registry = container._registry;
|
||||
|
||||
// Get indexes for bound types and iterate over them
|
||||
var length = container._metadata.GetEntries(ref key, out int[]? data);
|
||||
var length = container._metadata.GetMeta(ref key, out int[]? data);
|
||||
if (null != data)
|
||||
{
|
||||
for (var i = 1; i < length; i++)
|
||||
{
|
||||
var index = data[i];
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Value;
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Policies;
|
||||
|
||||
if (null != registration.Name && set.Add(registration.Name))
|
||||
{
|
||||
|
@ -340,13 +340,13 @@ namespace Unity
|
|||
}
|
||||
|
||||
// Get indexes for unbound types and iterate over them
|
||||
length = container._metadata.GetEntries(ref keyGeneric, out data);
|
||||
length = container._metadata.GetMeta(ref keyGeneric, out data);
|
||||
if (null != data)
|
||||
{
|
||||
for (var i = 1; i < length; i++)
|
||||
{
|
||||
var index = data[i];
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Value;
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Policies;
|
||||
|
||||
if (null != registration.Name && set.Add(registration.Name))
|
||||
{
|
||||
|
@ -382,13 +382,13 @@ namespace Unity
|
|||
var registry = container._registry;
|
||||
|
||||
// Get indexes and iterate over them
|
||||
var length = container._metadata.GetEntries(ref key, out int[]? data);
|
||||
var length = container._metadata.GetMeta(ref key, out int[]? data);
|
||||
if (null != data)
|
||||
{
|
||||
for (var i = 1; i < length; i++)
|
||||
{
|
||||
var index = data[i];
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Value;
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Policies;
|
||||
|
||||
if (null != registration.Name && set.Add(registration.Name))
|
||||
{
|
||||
|
@ -428,13 +428,13 @@ namespace Unity
|
|||
var registry = container._registry;
|
||||
|
||||
// Get indexes for bound types and iterate over them
|
||||
var length = container._metadata.GetEntries(ref key, out int[]? data);
|
||||
var length = container._metadata.GetMeta(ref key, out int[]? data);
|
||||
if (null != data)
|
||||
{
|
||||
for (var i = 1; i < length; i++)
|
||||
{
|
||||
var index = data[i];
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Value;
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Policies;
|
||||
|
||||
if (null != registration.Name && set.Add(registration.Name))
|
||||
{
|
||||
|
@ -454,13 +454,13 @@ namespace Unity
|
|||
}
|
||||
|
||||
// Get indexes for unbound types and iterate over them
|
||||
length = container._metadata.GetEntries(ref keyGeneric, out data);
|
||||
length = container._metadata.GetMeta(ref keyGeneric, out data);
|
||||
if (null != data)
|
||||
{
|
||||
for (var i = 1; i < length; i++)
|
||||
{
|
||||
var index = data[i];
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Value;
|
||||
var registration = (ExplicitRegistration)registry.Entries[index].Policies;
|
||||
|
||||
if (null != registration.Name && set.Add(registration.Name))
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using Unity.Policy;
|
||||
using Unity.Registration;
|
||||
using Unity.Storage;
|
||||
|
||||
namespace Unity.Utility
|
||||
|
@ -8,7 +9,7 @@ namespace Unity.Utility
|
|||
{
|
||||
#region Set
|
||||
|
||||
internal static void Set(this Registry<IPolicySet> registry, Type type, IPolicySet set)
|
||||
internal static void Set(this Registry registry, Type type, IPolicySet set)
|
||||
{
|
||||
var key = new HashKey(type);
|
||||
var targetBucket = key.HashCode % registry.Buckets.Length;
|
||||
|
@ -18,7 +19,7 @@ namespace Unity.Utility
|
|||
ref var candidate = ref registry.Entries[i];
|
||||
if (candidate.Key != key) continue;
|
||||
|
||||
candidate.Value = set;
|
||||
candidate.Policies = set;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -26,11 +27,11 @@ namespace Unity.Utility
|
|||
entry.Key = key;
|
||||
entry.Next = registry.Buckets[targetBucket];
|
||||
entry.Type = type;
|
||||
entry.Value = set;
|
||||
entry.Policies = set;
|
||||
registry.Buckets[targetBucket] = registry.Count++;
|
||||
}
|
||||
|
||||
internal static void Set(this Registry<IPolicySet> registry, Type type, string? name, IPolicySet policies)
|
||||
internal static void Set(this Registry registry, Type type, string? name, ExplicitRegistration registration)
|
||||
{
|
||||
var key = new HashKey(type, name);
|
||||
var targetBucket = key.HashCode % registry.Buckets.Length;
|
||||
|
@ -40,15 +41,17 @@ namespace Unity.Utility
|
|||
ref var candidate = ref registry.Entries[i];
|
||||
if (candidate.Key != key) continue;
|
||||
|
||||
candidate.Value = policies;
|
||||
candidate.Policies = registration;
|
||||
return;
|
||||
}
|
||||
|
||||
ref var entry = ref registry.Entries[registry.Count];
|
||||
entry.Key = key;
|
||||
entry.Next = registry.Buckets[targetBucket];
|
||||
entry.IsExplicit = true;
|
||||
entry.Type = type;
|
||||
entry.Value = policies;
|
||||
entry.Policies = registration;
|
||||
entry.Registration = new ContainerRegistration(type, registration);
|
||||
registry.Buckets[targetBucket] = registry.Count++;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче