Download & Extend

Dependency Injection

Put simply, a Dependency Injection Container alleviates the need for factories and the use of new in your code. Think of DiC as the new new. You will still need to write factories in some cases, but your code will not depend directly on them. Your code will be easier to change, unit test and reuse in other contexts.

This module enables Symfony's Dependency Injection component for Drupal 7 modules.

Requirements

Usage

  1. Add a dependency on this module to your module's .info file:
    dependencies[] = inject
  2. Thick Configuration > Performance > Dump configuration to disk checkbox to cache the dumped version of the container to disk.
  3. Thick Configuration > Performance > Compile configuration checkbox to compile the container before dumping.

The module comes with container dumping activated by default. In a developer environment you may deactivate this functionality to debug the container building process. Deactivating this feature adds a substantial performance hit as more meta-data (Yaml files, config, ...) has to be loaded into memory than might actually be necessary. This may not be relevant to scenarios where caching is in place, however hits hardly in scenarios where no caching is used.

Registering services

New in 7.x-2.0-beta7: You can now register services with Yaml files à-la Drupal 8. Name your file $module.services.yml and register your parameters and services directly in Yaml. See the test_inject.services.yml file provided as an example.

Deprecated: hook_inject_boot and hook_inject_init has been deprecated in favor of a unique hook_inject_build. This is more in-line with Drupal 8 where you register and build your container in Bundle through a unique method build. The two former hook will be removed in the 2.0 stable release!

Functional tests has been added in this release, you can see them in the Automated Test tab of project.

For a real example of a module leveraging the dependency overriding mechanism, you might have a look at Doctrine module. The Entity integration module overrides the doctrine.orm.driver to support both Schema API and Annotation Driven entities.

Documentation

Downloads

Recommended releases

Version Downloads Date Links
7.x-2.0-beta8 tar.gz (76.82 KB) | zip (155.94 KB) 2013-May-06 Notes

Development releases

Version Downloads Date Links
7.x-2.x-dev tar.gz (76.83 KB) | zip (155.96 KB) 2013-May-07 Notes

Project Information


Maintainers for Dependency Injection

  • Sylvain Lecoy - 35 commits
    last: 2 weeks ago, first: 12 weeks ago

Issues for Dependency Injection

To avoid duplicates, please search before submitting a new issue.
All issues
Bug reports
nobody click here