Configurator – Add different configs based on Module
- Marek Bartoš
- Nette Blogger | 1261
No, it's not. But depending on what is in these module-specific configs, some other solution probably exists.
- jeremy
- Member | 54
Here is my config file for services:
services:
- App\Router\RouterFactory::createRouter
- App\Backend\Services\BackendService(
%tempDir%
not(%debugMode%)
@application.application
)
- App\Frontend\Services\FrontendService(
not(%debugMode%)
)
Now, I'd like to have Backend services only loaded when I am in the Backend
Module.
The main reason is that I want to have the ability to create plugins for my app
and extend the app's functionality and should those plugins have their own
services, it would be nice if I didn't have to write each one in the main
config file.
Maybe there is another way?
Thanks
Last edited by jeremy (2022-01-16 17:43)
- Marek Bartoš
- Nette Blogger | 1261
Instance of service is not created unless you request that service from DI (via constructor, inject method, …).
Only downside is for each service is generated one method in compiled DI container. But you should not worry about that, compiled DIC can have tens of thousands lines of code and it will not affect performance even slightly.
To split services into multiple files, use include:
includes:
- Backend/wiring.neon
- Frontend/wiring.neon
If you plan to have optional plugins (e.g. in vendor directory), bootstrap is the way to go:
$configurator->addConfig(__DIR__ . '/../vendor/example/package/src/wiring.neon');
Last edited by Marek Bartoš (2022-01-16 18:04)