Dependency Injection
- Version 4.x
- Version 3.x
- Version 2.x
The Jaxon library allows to add classes and interfaces as parameters of Jaxon classes constructors.
class HelloWorld
{
protected $service;
public function __construct(ExampleInterface $service)
{
$this->service = $service;
}
}
The dependences are declared during the library configuration.
jaxon()->di()->set(ExampleInterface::class, function($di){
return new Example();
});
They will then be instanciated at the same time as Jaxon classes, when processing requests.