Dependency enumeration vs container validation #73
mindplay-dk
started this conversation in
Discussion
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I tried to implement the recently introduced
ServiceDependencyInterface
.service-provider/PSR-XX-provider.md
Lines 84 to 99 in 71e3975
My main reason for proposing this interface was "ahead of time" validation - in fact, it's the only example I know of that requires "dependency enumeration" is it's described in the PSR draft now. But it turns out, this interface does not enable validation, because my own container implementation actually internally has more information than just the list of dependencies - it also happens to know which ones are required or optional.
Now, we could continue down this path and add more information to the model, indicating optional dependencies - but there's no saying those are the only things a container could validate, so that approach seems limited, besides leading to more complexity.
After a lot of thinking, here's a different option to address the validation requirement more directly:
Service providers that are capable of performing validation would implement this optional interface - the requirement would be that containers/builders, if they support this feature, at the time of validation (for example, when a container-builder is asked to build it's first container, or when if a mutable container is directly asked to validate) they must call this method on all registered service providers, and the list of
$serviceIDs
must be complete, e.g. gathered from all calls togetFactories()
on all added service providers.This way, there are no restrictions on what a container-builder can validate ahead of time, before the container is created.
@XedinUnknown I'm particularly interested in your opinion, since you were an active debater in #54 - I'm curious if this approach would also work for Dhii, which takes quite a different approach from most containers? 🤔
Beta Was this translation helpful? Give feedback.
All reactions