Service providers are used to bootstrap your application with the injection of core classes and dependencies.
A service provider will have one or two methods: register() and/or boot(). The register method should only be used
to define parameters, define new services or extend services.
The boot method is called after all service providers have been registered.
<?php
declare(strict_types=1);
namespace Application\Provider;
use Codefy\Framework\Support\CodefyServiceProvider;
final class ExampleServiceProvider extends CodefyServiceProvider
{
public function register(): void
{
// Tell the Injector class to inject an instance of V8 any time
// it encounters an Engine type-hint
$this->codefy->alias(
original: \Engine::class,
alias: \V8::class
);
}
}
File: ./Cms/Application/Provider/ExampleServiceProvider.php
In the example above uses the register method, and within the method, The V8 class is an implementation of the
Engine interface. So, wherever Engine is a typehint, the Injector will resolve the dependency with the V8 class.
Register Service Provider
When you create a service provider, you need to register your service provider in bootstrap/providers.php.
Service providers use Qubus Injector.