operator == method
Equality comparison based on service type, lifetime, implementation type/instance/factory, and service key.
This matches .NET's ServiceDescriptor.Equals behavior where two descriptors are equal if they describe the same service registration.
Implementation
@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
if (other is! ServiceDescriptor) {
return false;
}
// Service type and lifetime must match
if (serviceType != other.serviceType || lifetime != other.lifetime) {
return false;
}
// Service key must match (including null == null)
if (serviceKey != other.serviceKey) {
return false;
}
// For instance-based descriptors, compare instances
if (_implementationInstance != null ||
other._implementationInstance != null) {
return identical(
_implementationInstance,
other._implementationInstance,
);
}
// For factory-based descriptors, compare factories by identity
if (_implementationFactory != null ||
other._implementationFactory != null) {
return identical(
_implementationFactory,
other._implementationFactory,
);
}
// Both are null
return true;
}