So what's this all about?

Autowiring Bundle is an inofficial
Symfony 2
bundle that provides the ability to define services by annotations
(by php doc-comments that are interpreted as class metadata) and
autowiring by naming convention and type resolution.
These features are both enabled for pre-defined services
as well as any container aware class (beeing more precisely:
for any class).
Examples
A few LOC's can tell more than thousand words, so let's implement a WelcomeController for a freshly created Symfony 2 application.
<?php namespace Acme\DemoBundle\Controller; use Ifschleife\Bundle\AutowiringBundle\Annotations\Service; use Ifschleife\Bundle\AutowiringBundle\Annotations\Inject; use Symfony\Component\Templating\EngineInterface; /** * @Service */ class WelcomeController { /** * @var EngineInterface */ private $templating; /** * @param EngineInterface $templating * @Inject */ public function __construct(EngineInterface $templating) { $this->templating = $templating; } public function indexAction() { return $this->templatingService->renderResponse('AcmeDemoBundle:Welcome:index.html.twig'); } }
No abstract ActionController base class is needed at all, the dependencies (the templating) is resolved by introspecting the constructor´s argument types.
Another example, now wired by naming conventions:
<?php namespace Acme\DemoBundle\Controller; use Ifschleife\Bundle\AutowiringBundle\Annotations\Service; /** * @Service */ class WelcomeController { /** * @var Symfony\Bundle\TwigBundle\TwigEngine */ private $templatingService; public function indexAction() { return $this->templatingService->renderResponse('AcmeDemoBundle:Welcome:index.html.twig'); } }
Or address the service explicitely to obviate dependency resolver conflicts:
//... use Ifschleife\Bundle\AutowiringBundle\Annotations\Inject; /** * @Service */ class WelcomeController { /** * @var Symfony\Bundle\TwigBundle\TwigEngine * @Inject("templating") */ public function __construct(EngineInterface $templating) //...
There are many more means provided that enable you to steer the service resolving by enriching your classes with metadata information (annotation, variable namining conventions).
Additionally, the behaviour of the dependenceny resolver is highly configurable
For learning more, please refer to the Documentation page or read the README.rst file in the Resources/doc folder of the bundle.
Learn more about dependency injection
Warning
NOTE: This bundle is in a very early state of development. There is yet a lack of code coverage and no guarantee that it`ll work at any circumstances. Thus i want to make one advice:
Don´t ever use this bundle in production environments until this warning has disappeared!
For now, this bundle must be understood as a case-study for determining use-cases and solutions to them. It is an experiment to make out what may be achieved by dependency-autowiring, to determine which features are considered “good”, and ”bad“ in the sense of “too complex”, “too magically” or simply redundant.
So, if you are interested, read the docs, download the bundle and give it a try.
Thank you!
