update: updating 39 pass 9 fail

This commit is contained in:
Patrick Stewart 2024-12-23 08:26:38 -07:00
parent c268cb5b1d
commit 2e3a9cbc7c

View file

@ -415,12 +415,6 @@ class Container implements ContainerContract, Map<String, dynamic> {
return instance; return instance;
} }
@override
T make<T>(String abstract, [List<dynamic>? parameters]) {
var result = resolve(abstract, parameters);
return _applyExtenders(abstract, result, this) as T;
}
@override @override
void singleton(String abstract, [dynamic concrete]) { void singleton(String abstract, [dynamic concrete]) {
bind(abstract, concrete ?? abstract, shared: true); bind(abstract, concrete ?? abstract, shared: true);
@ -442,22 +436,8 @@ class Container implements ContainerContract, Map<String, dynamic> {
_instances[abstract] = closure(_instances[abstract], this); _instances[abstract] = closure(_instances[abstract], this);
} }
if (_bindings.containsKey(abstract)) { if (!_bindings.containsKey(abstract)) {
var originalConcrete = _bindings[abstract]!['concrete']; bind(abstract, (Container c) => abstract);
_bindings[abstract]!['concrete'] = (Container c) {
var result = originalConcrete is Function
? originalConcrete(c)
: (originalConcrete ?? abstract);
return _applyExtenders(abstract, result, c);
};
} else {
bind(abstract, (Container c) {
dynamic result = abstract;
if (c.bound(abstract) && abstract != c._getConcrete(abstract)) {
result = c.resolve(abstract);
}
return _applyExtenders(abstract, result, c);
});
} }
// Handle aliases // Handle aliases
@ -471,20 +451,35 @@ class Container implements ContainerContract, Map<String, dynamic> {
}); });
} }
@override
T make<T>(String abstract, [List<dynamic>? parameters]) {
var result = resolve(abstract, parameters);
return _applyExtenders(abstract, result, this) as T;
}
dynamic _applyExtenders(String abstract, dynamic result, Container c) { dynamic _applyExtenders(String abstract, dynamic result, Container c) {
if (_extenders.containsKey(abstract)) { var appliedExtenders = <Function>{};
for (var extender in _extenders[abstract]!) {
result = extender(result, c); void applyExtendersForAbstract(String key) {
} if (_extenders.containsKey(key)) {
} for (var extender in _extenders[key]!) {
// Apply extenders for aliases as well if (!appliedExtenders.contains(extender)) {
_aliases.forEach((alias, target) { result = extender(result, c);
if (target == abstract && _extenders.containsKey(alias)) { appliedExtenders.add(extender);
for (var extender in _extenders[alias]!) { }
result = extender(result, c);
} }
} }
}
applyExtendersForAbstract(abstract);
// Apply extenders for aliases
_aliases.forEach((alias, target) {
if (target == abstract) {
applyExtendersForAbstract(alias);
}
}); });
return result; return result;
} }