configuration.rst 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Configuration
  2. =============
  3. Introduction
  4. ------------
  5. By default, you can only use the provided :doc:`annotations <annotations>` on your
  6. non-service controllers; no other directories are scanned.
  7. However, if you also would like to use annotations to configure your regular services,
  8. you can configure more locations as demonstrated below.
  9. Configuration Locations
  10. -----------------------
  11. If you would like to configure services in a bundle of yours via annotations, or
  12. have some services outside of any bundles structure such as in your ``src/`` directory,
  13. you can make use of the following configuration options, so that the bundle will pick
  14. them up, and add them to your dependency injection container:
  15. .. configuration-block ::
  16. .. code-block :: yaml
  17. jms_di_extra:
  18. locations:
  19. all_bundles: false
  20. bundles: [FooBundle, AcmeBlogBundle]
  21. directories: ["%kernel.root_dir%/../src"]
  22. .. code-block :: xml
  23. <jms-di-extra>
  24. <locations all-bundles="false">
  25. <bundle>FooBundle</bundle>
  26. <bundle>AcmeBlogBundle</bundle>
  27. <directory>%kernel.root_dir%/../src</directory>
  28. </locations>
  29. </jms-di-extra>
  30. .. tip ::
  31. For optimal development performance (in production there is no difference either way),
  32. it is recommended to explicitly configure the directories which should be scanned for
  33. service classes, and not rely on the ``all_bundles`` configuration option.
  34. Automatic Controller Injections
  35. -------------------------------
  36. This bundle allows you to configure injection for certain properties, and methods
  37. of controllers automatically. This is most useful for commonly needed services
  38. which then do not need to be annotated explicitly anymore.
  39. .. configuration-block ::
  40. .. code-block :: yaml
  41. jms_di_extra:
  42. automatic_controller_injections:
  43. properties:
  44. request: "@request"
  45. router: "@router"
  46. method_calls:
  47. setRouter: ["@router"]
  48. .. code-block :: xml
  49. <jms-di-extra>
  50. <automatic-controller-injections>
  51. <property name="request">@request</property>
  52. <property name="router">@router</property>
  53. <method-call name="setRouter">@router</method-call>
  54. </automatic-controller-injections>
  55. </jms-di-extra>
  56. If you controller has any of the above properties, or methods, then you do not need
  57. to add an @Inject annotation anymore, but we will automatically inject the configured
  58. services for you. However, if you do declare an @Inject annotation it will automatically
  59. overwrite whatever you have configured in the above section.