michael-rubel/laravel-enhanced-container
A lightweight extension for Laravel’s service container, offering convenient helpers for binding, resolving, and managing dependencies. Simplify contextual bindings, singletons, and instance handling while keeping service providers clean, expressive, and easier to test.
Architecture fit — The package augments Illuminate\Container\Container rather than replacing Laravel's binding model, so it is additive at the API level and cross-cutting at the runtime level. It fits best in large, modular or DDD-leaning codebases where service providers have become a registration dumping ground and where interface-to-implementation maps are numerous: attribute-driven binding (#[Bind], #[Singleton], #[Scoped], #[Tag], registration/resolution hooks) colocates a class's lifecycle with the class itself. For a typical CRUD application the value is marginal — native bind, singleton, scoped, and when() cover the large majority of needs, and the package mostly buys ergonomics plus a declarative convention.
Integration feasibility — MIT licensed, Composer-only, no infrastructure dependencies, no external service requirements. Installation is trivial; adoption is not. Because the package extends the container itself, the app must swap in the enhanced container during bootstrap — a single-line but globally scoped change that must be validated across the entire application, including third-party packages. Attribute adoption, by contrast, is per-class and fully opt-in, which permits a genuine incremental rollout.
Technical risk
Application::useContainer-style bootstrapping), so the supported Laravel window is a hard constraint, not a soft one.scoped and cached-instance behavior under Octane, queue workers, and between tests must be proven, not assumed.Key questions
Application::configure()), package discovery, and existing providers?php artisan optimize, config/route caching, and container pre-resolution?reset/flush behave for test isolation and worker boundaries?when() contextual bindings and third-party #[Inject]-style attributes conflict or take precedence?Stack fit — Laravel 10/11/12 on PHP 8.1+ (attributes require 8.0+; confirm the package floor). No changes to database, queue, cache, or frontend stacks. Compatible in principle with Octane and RoadRunner, but scoped-binding correctness under long-running workers is the one area that needs explicit verification before production.
Migration path — Three phases, each independently revertible:
Compatibility — Explicitly test against: existing when()/contextual bindings; other container-manipulating packages; optimize/cache commands; providers registered via package discovery; and any code depending on instance() object identity. Pin the package to a minor and treat Laravel major upgrades as a gate that requires re-validating the package first.
Sequencing — Container swap → pilot module → benchmark baseline → documentation and convention → broader adoption. Keep the swap behind a config flag or a dedicated bootstrapper so rollback is a one-line revert. Establish a resolution benchmark on your container-heaviest endpoint (cold boot and per-request) before the swap, otherwise you will have no way to attribute any latency regression later.
Maintenance — You are essentially the primary consumer. Budget a recurring quarterly compatibility review tied to the Laravel release calendar, and keep fork-and-patch as a standing option — MIT licensing and a small, readable codebase make this cheap. Do not let the package become tribal knowledge: record the decision and the container-swap mechanism in an ADR.
Support — No vendor, no SLA, community issues only. Require at least two engineers on the team who can read the package's internals, so the org is not dependent on a single champion.
Scaling — Container resolution sits on every request's critical path. Reflection-driven attribute resolution should be measured at p95 and mitigated with caching/pre-resolution if it shows up. Horizontal scaling is unaffected; what matters is state correctness across workers, which is a correctness problem rather than a throughput problem.
Failure modes
Illuminate\Container\Container breaking under the swap → mitigated by shadow deployment and an inventory of container-touching dependencies.Ramp-up — Low syntactic learning curve for anyone fluent in Laravel's container; the real cost is establishing convention, which is roughly a half-day workshop plus a written decision guide. Total estimate: one to two sprints of a senior engineer for swap, pilot module, benchmarks, and documentation. Recommendation: pilot and measure, but do not standardize organization-wide until the setup has survived at least one Laravel major upgrade with the package pinned and validated.
How can I help you explore Laravel packages today?