Dependency Injection (DI) is a design pattern that allows you to inject automatically created services (or objects, etc.) without creating them manually. Viewi handles DI automatically by following these rules:
All other DI rules are planned for future development. And you can always request it as feature on our github page so we will know how important it is for you.
Easy:
<?php namespace Application\Components\Views\Demo\ServicesAndModels; use Application\Components\Services\Demo\CounterState; use Viewi\BaseComponent; class ServicesExample extends BaseComponent { public CounterState $counter; public function __init(CounterState $counterState) { $this->counter = $counterState; } }
<?php namespace Components\Services; use Viewi\Common\ClientRouter; use Viewi\Common\HttpClient; class AuthService { private HttpClient $http; private ClientRouter $router; public function __construct(HttpClient $httpClient, ClientRouter $clientRouter) { $this->http = $httpClient; $this->router = $clientRouter; } }