config/README.md
This directory contains PSR-11 container configuration files for dependency injection.
Dependency injection makes it easier to write robust and testable code by decoupling specific implementations.
For more information:
The DI container is not yet fully integrated into OpenEMR. Once it is, here's how things will work:
get() the dependency from the container and feed it the request to processOnly the application entrypoints should be directly interacting with the container. The container will not be passed around to various services.
Services added here must support constructor-based dependency injection. This means:
$GLOBALS, OEGlobalsBag, service locators, or static singletons to obtain dependenciesBy default, the container itself will reuse services as they are requested. Like (just about) all PHP code, there is still a fresh instance per request.
In the rare case that this behavior is inappropriate for the service, the definition can be wrapped in a factory() call.
Generally when this is true, it's a sign that the class has too much internal state.
See the container library documentation for syntax and usage examples.
While there's no technical requirement around organization, config files should be organized into logical groups:
env.php - Environment/configuration valuesdatabase.php - Database-related servicespsr.php - PSR interface-to-implementation mappingsservices.php - General application servicesIf code is not a good fit, other files can be added. Services will probably get large, and it can be split apart if and when needed.
Many existing services in OpenEMR do not yet follow DI principles. Before wiring a legacy service into the container:
$GLOBALS, OEGlobalsBag, or various singletons for service accessDo not add services that still rely on global state or service locators. Migrate them first.