tryAddIterable method
Adds a ServiceDescriptor if an existing descriptor with the same
ServiceDescriptor.serviceType and an implementation that does not
already exist in services.
This matches .NET's TryAddEnumerable behavior: it only prevents adding duplicate descriptors (same type, lifetime, implementation, and key). Multiple services of the same type with different implementations are allowed.
Implementation
void tryAddIterable(ServiceDescriptor descriptor) {
var count = length;
for (var i = 0; i < count; i++) {
var existing = this[i];
// Check if the exact same descriptor already exists
// This uses ServiceDescriptor's equality operator which compares
// service type, lifetime, implementation (factory/instance), and key
if (existing == descriptor) {
// Exact duplicate found, don't add
return;
}
}
// No duplicate found, safe to add
add(descriptor);
}