Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Injector Laravel Package

yiisoft/injector

yiisoft/injector is a lightweight PHP dependency injection container for building objects and wiring dependencies via constructor, method, and property injection. Supports factories, config-based definitions, and PSR-friendly integration for Yii apps and beyond.

Deep Wiki
Context7

yiisoft/injector is a lightweight dependency injection library for PHP that helps you construct objects and wire dependencies with minimal configuration. It focuses on pragmatic autowiring and clean object creation, making it easy to adopt in both small apps and larger frameworks.

Use it to centralize instantiation logic and keep your codebase decoupled, testable, and maintainable while staying framework-agnostic.

  • Autowires dependencies via type hints and constructors
  • Configurable bindings/definitions for interfaces and classes
  • Supports callable invocation with dependency resolution
  • Works with PSR containers and common PHP ecosystems
  • Encourages clean architecture and easier unit testing
Frequently asked questions about Injector
Why would I use yiisoft/injector in a Laravel app when Laravel already has Illuminate\Container?
You wouldn’t—Laravel’s built-in container is deeply optimized for the framework, supporting autowiring, contextual binding, and factory definitions natively. yiisoft/injector adds redundant complexity without clear benefits, as it lacks Laravel-specific integrations (e.g., Request or Auth resolution) and risks conflicts in service resolution.
Can I integrate yiisoft/injector alongside Laravel’s container without breaking anything?
Technically possible but highly discouraged. Running two containers introduces ambiguity in service resolution, debugging complexity, and potential runtime errors. Laravel’s container is tightly coupled with its service providers, middleware, and events, making dual-container management unsustainable.
Does yiisoft/injector support Laravel’s autowiring or service providers?
No, it doesn’t. yiisoft/injector is framework-agnostic and lacks Laravel-specific features like autowiring, contextual binding, or integration with Laravel’s service provider bootstrapping. You’d need to manually register every dependency, defeating Laravel’s conventions.
What Laravel versions does yiisoft/injector officially support?
None. yiisoft/injector is not designed for Laravel and has no official Laravel version compatibility. While it may work with any PHP version Laravel supports, it won’t integrate with Laravel’s core systems (e.g., Artisan, Facades, or middleware).
How would testing change if I used yiisoft/injector instead of Laravel’s container?
Testing would become more cumbersome due to the lack of Laravel-specific testing tools (e.g., mocking Request or Auth instances). You’d need to manually configure test bindings, and stack traces would mix Laravel and yiisoft contexts, making debugging harder. Laravel’s container is already optimized for testing.
Are there performance benefits to using yiisoft/injector in Laravel?
No, there are no meaningful performance gains. Laravel’s Illuminate\Container is highly optimized for the framework’s use cases, including lazy loading and caching. yiisoft/injector’s lightweight design doesn’t translate to advantages in a Laravel context and may even introduce overhead from dual-container management.
Can I use yiisoft/injector for a reusable Laravel package instead of the framework’s container?
Only if you isolate it strictly from Laravel’s container and document the requirement clearly for consumers. However, this would force package users to manage two DI systems, which is impractical. Laravel packages should leverage Illuminate\Container for consistency with the ecosystem.
What are the risks of migrating from Laravel’s container to yiisoft/injector?
Risks include breaking core Laravel functionality (e.g., middleware, events), ambiguous service resolution conflicts, and increased debugging complexity. Overriding Laravel’s Application class or service providers would likely introduce runtime errors and violate framework conventions.
Does yiisoft/injector support callable or factory injection like Laravel’s container?
Yes, but the implementation is less integrated. yiisoft/injector supports callables and factories, but Laravel’s container handles these natively with better tooling (e.g., `app()->makeWith()`). Switching would require rewriting bindings and losing Laravel-specific optimizations.
Are there alternatives to yiisoft/injector that work better with Laravel?
Yes—stick with Laravel’s Illuminate\Container or consider specialized packages like Laravel’s own `laravel/container` or `php-di/php-di` (with Laravel-specific bridges). These integrate seamlessly with Laravel’s ecosystem without introducing redundancy or conflicts.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport