aura/di
Aura.Di is a PSR-11 dependency injection container for PHP 8+ with constructor and setter injection, interface and trait awareness, configurable wiring with inheritance, and support for serialization. Installable via Composer and fully documented.
#[Service], #[Instance], #[Value], and #[Blueprint] for declarative configuration, reducing boilerplate compared to Laravel’s traditional bind()/singleton() methods.Illuminate/Container with Aura.Di’s Container while maintaining PSR-11 compatibility.AppServiceProvider) can adapt to Aura.Di’s attribute-based or programmatic configuration.app()->make()) remains unchanged, but under the hood uses Aura.Di’s resolver.CompositeContainer (supported in Aura.Di 4.x+) for gradual migration.bind()/singleton() with Aura.Di’s #[Service] or programmatic set().app() helper and Illuminate/Container facade are tightly coupled to the container implementation. Replacing the container requires facade/method overrides or a custom facade (e.g., Aura\Di\Container).app()->make() uses contextual binding; Aura.Di’s contextual parameters must be manually configured if relying on this feature.ContainerCompileInterface) reduces runtime overhead but adds build-time complexity (e.g., generating class maps).lazyGet() is more granular than Laravel’s lazy containers but may require adjustments in eager-loading strategies (e.g., AppServiceProvider::boot()).composer/class-map-generator for scanning annotated classes, adding a build dependency.defer: true) interact with Aura.Di’s compiled blueprints?#[Service] attributes replace Laravel’s bindWhen() or conditional binding?bootstrap/cache/services.php)?tinker or debugbar work seamlessly with Aura.Di?#[Route])?Illuminate/Container with Aura\Di\Container in config/app.php:
'container' => [
'bindings' => Aura\Di\Container::class,
'contextual' => Aura\Di\ContextualContainer::class,
],
bind() calls with:
$this->container->set(MyService::class, fn() => new MyService(deps));
// OR via attributes:
#[Service(MyService::class)]
class MyServiceConfig {}
#[Service]
class AuthMiddleware implements Middleware {
public function __construct(#[Service] AuthManager $auth) {}
}
Mockery/PHPUnit container mocks with Aura.Di’s AbstractContainerConfigTest.CompositeContainer to bridge Laravel’s and Aura.Di’s containers:
$laravelContainer = new Illuminate\Container\Container();
$auraContainer = new Aura\Di\Container($laravelContainer);
bind('App\Services\Foo', fn() => new Foo()) to:
#[Service(App\Services\Foo::class)]
class FooConfig {}
class AuraContainerFacade extends Illuminate\Support\Facades\Facade {
protected static function getFacadeAccessor() { return 'aura.container'; }
}
config/app.php to use Aura\Di\Container as the default.app()->make()) works unchanged.#[Instance] can replace Laravel’s singleton() but may need custom logic for grouped singletons.config/app.php and container facade.bind()/singleton() to Aura.Di’s API.bind() calls).How can I help you explore Laravel packages today?