Problem
The php-fast-forward/container package currently exposes only singleton-style service/factory behavior, which makes it impossible to define dependencies that must be rebuilt on every get() call. This blocks use cases that rely on ephemeral collaborators, non-shared adapters, and short-lived orchestration objects.
Proposal
Introduce explicit transient factory support in the container so certain factory definitions bypass the shared-instance cache and are executed on each resolution. Singleton behavior should remain the default and continue to be the compatibility-preserving mode.
Goals
- Add a dedicated, explicit API surface to register transient factories.
- Keep existing registrations singleton by default for backward compatibility.
- Preserve current container entrypoint semantics and exception behavior.
- Ensure container internals expose enough visibility to detect and test shared vs transient resolution paths.
Expected Behavior
- A dependency registered as transient is instantiated (or rebuilt) every time the container resolves it.
- Singleton registrations continue returning the same shared instance across calls.
- Existing usages that rely on current singleton defaults remain unchanged and passing.
Implementation Strategy
- Review the container resolution pipeline to identify where instances are currently cached and reused.
- Add metadata/flags to mark factory definitions as transient.
- Add a public registration API (or extension of an existing one) for transient factories.
- Update resolution logic to skip cache write/read for transient definitions while keeping singleton caching unchanged.
- Add unit tests covering:
- transient factory returns different instance per
get()
- singleton keeps the same instance
- mixed usage across chained dependencies behaves deterministically
- Update container docs/README to show transient registration examples.
Non-goals
- No dependency graph redesign for external container integrations.
- No automatic constructor auto-discovery changes.
- No changes to PHP type system contracts unrelated to lifetime behavior.
Functional Criteria
Architectural / Isolation Criteria
- MUST: The core logic MUST be isolated into dedicated classes or services instead of living inside command or controller entrypoints.
- MUST: Responsibilities MUST be separated across input resolution, domain logic, processing or transformation, and output rendering when the change is non-trivial.
- MUST: The command or controller layer MUST act only as an orchestrator.
- MUST: The implementation MUST avoid tight coupling between core behavior and CLI or framework-specific I/O.
- MUST: The design MUST allow future extraction or reuse with minimal changes.
- MUST: The solution MUST remain extensible without requiring major refactoring for adjacent use cases.
Problem
The
php-fast-forward/containerpackage currently exposes only singleton-style service/factory behavior, which makes it impossible to define dependencies that must be rebuilt on everyget()call. This blocks use cases that rely on ephemeral collaborators, non-shared adapters, and short-lived orchestration objects.Proposal
Introduce explicit transient factory support in the container so certain factory definitions bypass the shared-instance cache and are executed on each resolution. Singleton behavior should remain the default and continue to be the compatibility-preserving mode.
Goals
Expected Behavior
Implementation Strategy
get()Non-goals
Functional Criteria
Architectural / Isolation Criteria