Answer the question
In order to leave comments, you need to log in
What is the best practice for connecting DI in Bitrix?
hello, can I read somewhere or ask you about connecting DI in Bitrix?
I want to put the simplest pimple container, https://pimple.symfony.com/
in order to pull the necessary services and classes from it, I'm interested in the specifics:
1) where is it better to write (dbconn\init) its initialization,
2) how to declare the container itself, so that it is convenient reach it (global)?
now I am writing composer autoload in dbconn and loading environment variables
if (!file_exists($autoloadPathDbconn= realpath(__DIR__).'/../../vendor/autoload.php')) {
$autoloadPathDbconn= realpath(__DIR__).'/../../vendor/autoload.php';
require_once($autoloadPathDbconn) ;
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(realpath(__DIR__).'/../../');
$dotenv->load();
}
define("BX_USE_MYSQLI", true);
define("DBPersistent", false);
.......
$container = new Container();
// define some services
$container['session_storage'] = function ($c) {
return new SessionStorage('SESSION_ID');
};
AddEventHandler("main", "OnBeforeProlog", array("Page", "OnBeforePrologHandler"));
global $container;
.....
Answer the question
In order to leave comments, you need to log in
Available from version main 20.5.400
Service Locator https://dev.1c-bitrix.ru/learning/course/index.php...
Locator registration https://dev.1c-bitrix.ru/learning/course/index .php...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question