Dependency Injection
Dependency injection in Semitexa PHP: declaring services, contracts, readonly and mutable injection, factories and configuration injection.
-
DI Canon
One canonical DI path for container-managed classes: protected property attributes, no constructor arguments, validated at boot and enforced by lint:di.
-
Declaring a Service
#[AsService] makes a plain class a worker-scoped singleton that the container builds and injects, and this page shows when you do not need it.
-
Readonly Injection
The default tier: one instance per worker, injected into a protected property, with optional injection for dependencies that may not be installed.
-
Mutable Injection
#[ExecutionScoped] opts a class into a per-execution clone; #[InjectAsMutable] marks the properties re-injected on that clone.
-
Factory Injection
#[InjectAsFactory] injects a factory that picks a contract implementation by backed-enum key. Execution-scoped implementations come back fresh each time.
-
Configuration Injection
#[Config] reads a scalar from the environment into a typed property, with a default in code. It is the only supported way a service reads env.
-
Service Contracts
One module declares an interface, implementations advertise themselves with SatisfiesServiceContract, and the active one is visible in contracts:list.
-
Resolving Service Contracts
Seeing which implementation is bound to a contract, using a resolver as a factory, and the Factory* naming convention for choosing by key.
-
Discovery Contributors
How a package teaches boot-time discovery to recognise its own attribute, with priority ordering and per-class error isolation.