Skip to content

Commit 4abc37b

Browse files
committed
Fixing Microsoft.DependencyInjection compatibility tests
1 parent d26230f commit 4abc37b

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

src/Storage/LinkedRegistry.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,43 @@ internal class LinkedRegistry : LinkedNode<string, IPolicySet>,
2222

2323
public LinkedRegistry(string key, IPolicySet value)
2424
{
25+
_count = 1;
2526
Key = key;
2627
Value = value;
2728
}
2829

30+
public LinkedRegistry(HashRegistry registry)
31+
{
32+
// TODO: Implement this
33+
throw new NotImplementedException();
34+
}
35+
2936
#endregion
3037

38+
public void Append(string name, IPolicySet value)
39+
{
40+
LinkedNode<string, IPolicySet> node;
41+
LinkedNode<string, IPolicySet> last = null;
42+
43+
for (node = this; node != null; node = node.Next)
44+
{
45+
if (name == node.Key)
46+
{
47+
node.Key = Guid.NewGuid().ToString();
48+
}
49+
last = node;
50+
}
51+
52+
// Not found, so add a new one
53+
last.Next = new LinkedNode<string, IPolicySet>
54+
{
55+
Key = name,
56+
Value = value
57+
};
58+
59+
_count++;
60+
}
61+
3162

3263
#region IRegistry
3364

src/UnityContainer.Registration.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,55 @@ private IRegistry<string, IPolicySet> Get(Type type)
316316

317317
#region Registration manipulation
318318

319+
320+
// Register new and return overridden registration
321+
internal IPolicySet AppendNew(Type type, string name, InternalRegistration registration)
322+
{
323+
var collisions = 0;
324+
var hashCode = (type?.GetHashCode() ?? 0) & 0x7FFFFFFF;
325+
var targetBucket = hashCode % _registrations.Buckets.Length;
326+
lock (_syncRoot)
327+
{
328+
for (var i = _registrations.Buckets[targetBucket]; i >= 0; i = _registrations.Entries[i].Next)
329+
{
330+
ref var candidate = ref _registrations.Entries[i];
331+
if (candidate.HashCode != hashCode ||
332+
candidate.Key != type)
333+
{
334+
collisions++;
335+
continue;
336+
}
337+
338+
if (candidate.Value is HashRegistry registry)
339+
{
340+
candidate.Value = new LinkedRegistry(registry);
341+
}
342+
343+
var existing = candidate.Value as LinkedRegistry;
344+
Debug.Assert(null != existing);
345+
346+
existing.Append(name, registration);
347+
348+
return null;
349+
}
350+
351+
if (_registrations.RequireToGrow || ListToHashCutPoint < collisions)
352+
{
353+
_registrations = new Registrations(_registrations);
354+
targetBucket = hashCode % _registrations.Buckets.Length;
355+
}
356+
357+
ref var entry = ref _registrations.Entries[_registrations.Count];
358+
entry.HashCode = hashCode;
359+
entry.Next = _registrations.Buckets[targetBucket];
360+
entry.Key = type;
361+
entry.Value = new LinkedRegistry(name, registration);
362+
_registrations.Buckets[targetBucket] = _registrations.Count++;
363+
364+
return null;
365+
}
366+
}
367+
319368
// Register new and return overridden registration
320369
private IPolicySet AddOrUpdate(Type type, string name, InternalRegistration registration)
321370
{

0 commit comments

Comments
 (0)