Dependency Injection

Overview

Dependency Injection in Sukarix is facilitated through the singleton class Injector::instance()->get('access'). This method allows for easy and efficient management of dependencies within your application.

Example Usage

In this example, access is the default ACL Middleware tied to f3-access:

$access = Injector::instance()->get('access');

Additionally, the Injector can find an object from its class directly:

$multiLang = Injector::instance()->get(\Multilang::class);

Configuration & Default Dependencies

These default classes can be easily changed or overridden by updating the classes.ini file. The default configuration is in the table below:

KeyClass
mailerSukarix\Mail\MailSender
notifierSukarix\Notification\Notifier
sessionSukarix\Core\Session
i18nSukarix\Helpers\I18n
assetsSukarix\Helpers\Assets
access\Access
eventsSugar\Event
template\Template
htmlSukarix\Helpers\HTML
multi_language\Multilang
receiverSukarix\Helpers\Receiver

Creating Injectable Singletons

For classes that should be singletons with behaviors, they must extend the Sukarix\Core\Tailored class. This ensures the framework can automatically integrate their behaviors. More details on these behaviors can be found in the Behaviors section of the documentation.

Instantiating an injectable singleton object

There is no need to manually instantiate the injected object, Sukarix will do it for you.

Storing DI Classes

The F3 \Registry class is used to store these dependency-injected classes, ensuring they are easily accessible throughout your application. However, it is recommended to use the Injector class that already wraps this functionality, as it provides additional features and should be preferred over direct usage of \Registry.