Add contextual bindings and PHP 8 attributes support#20
Conversation
There was a problem hiding this comment.
💡 Codex Review
container/src/Container/DependencyCacheManager.php
Lines 45 to 53 in 307bc6d
Contextual bindings are resolved based on the class currently on the build stack, yet resolveDependencies() caches the dependency list only by the class being instantiated. When a shared service is resolved in multiple contexts with different when()->needs()->give() rules, the first cached dependency set is reused and later contextual bindings are ignored (e.g. Service resolved for UserController caches a FileLogger and AdminController subsequently receives the same instance instead of its DatabaseLogger). The cache keys need to incorporate the requesting context or be disabled for contextual bindings to avoid injecting incorrect implementations.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
📓 Summary
This PR adds two major developer experience improvements to the container:
🏗️ Contextual Bindings
Different classes can now receive different implementations of the same interface:
#[Inject] - Override type hints
#[Singleton] - Single instance
#[Factory] - New instances