- Can I use nette/di as Laravel’s primary dependency injection container?
- No, nette/di is not designed for Laravel’s ecosystem. Its compiled container architecture conflicts with Laravel’s runtime binding system (e.g., service providers, facades). Use it only for non-Laravel components via PSR-11 adapters like league/container.
- How do I install nette/di in a Laravel project?
- Run `composer require nette/di` in your project root. Avoid direct integration with Laravel’s container; instead, use it for standalone services or wrap it with a PSR-11 adapter for compatibility.
- Does nette/di support Laravel’s service providers (register/boot methods)?
- No, nette/di lacks Laravel’s service provider lifecycle hooks. You’d need a custom ServiceProvider to manually sync nette/di definitions with Laravel’s container, which adds complexity.
- Will nette/di work with Laravel’s facades (e.g., Cache::get())?
- No, facades rely on Laravel’s container resolution methods (e.g., `app()`), which nette/di cannot replicate. Use nette/di only for services not tied to Laravel’s facade system.
- Can I use nette/di’s autowiring alongside Laravel’s autowiring?
- Not seamlessly. Laravel’s autowiring is runtime-based, while nette/di compiles dependencies statically. Mixing them risks unpredictable resolution, especially for circular dependencies or shared services.
- What Laravel versions support nette/di via PSR-11 adapters?
- nette/di works with any Laravel 8.0+ version, but integration requires a PSR-11 adapter (e.g., league/container). Test thoroughly—Laravel’s container expects runtime flexibility, while nette/di is optimized for compile-time rigidity.
- How do I configure nette/di for Laravel (e.g., Neon/YAML files)?
- nette/di uses Neon/YAML or PHP-based service definitions, which don’t align with Laravel’s PHP-class providers. You’d need a custom ServiceProvider to load nette/di configs into Laravel’s container, adding maintenance overhead.
- Is nette/di faster than Laravel’s native container?
- Yes, nette/di’s compiled container is significantly faster for static services, but this comes at the cost of runtime flexibility. If using a PSR-11 adapter, expect ~20-30% slower resolution than Laravel’s native container.
- Are there alternatives to nette/di for compiled DI in Laravel?
- For compiled DI, consider PHP 8.1’s native `return new self()` or Laravel’s `make:` command for optimized containers. For PSR-11 compliance, explore `league/container` or `php-di/php-di` (though neither offers compile-time performance).
- How do I debug nette/di services in a Laravel app?
- nette/di’s Tracy debugger won’t integrate with Laravel’s debugbar. Use custom logging (e.g., `error_log`) or wrap nette/di services in Laravel’s container for debugging via `app()->make()` or `app()->bind()`.