Download the PHP package skrz/autowiring-bundle without Composer
On this page you can find all versions of the php package skrz/autowiring-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download skrz/autowiring-bundle
More information about skrz/autowiring-bundle
Files in skrz/autowiring-bundle
Package autowiring-bundle
Short Description Annotation-based autowiring for Symfony 4 dependency injection container
License MIT
Informations about the package autowiring-bundle
Skrz\Bundle\AutowiringBundle
Annotation-based autowiring for Symfony 4 dependency injection container
Installation
Add as Composer dependency:
Then add SkrzAutowiringBundle
to Symfony Kernel:
Usage
Annotate your application components using @Component
annotation and its subclasses, or so called "stereotypes".
Predefined stereotypes are @Controller
, @Repository
, and @Service
, e.g.:
Create your own application stereotypes by subclassing @Component
.
Constructor dependency injection
SomeService
is automatically injected into HomepageController
instance during creation in container.
Note that constructor is ALWAYS autowired if there is not enough arguments
specified in services.yml
. If you really
do not want the constructor to be autowired, add the service to ignored_services
configuration directive.
Note: if you need to specify some of the constructor arguments and autowire other constructor aurguments, you need to configure your service the following way:
The $someService
argument is autowired and the $someParameter
argument is injected depending on the configuration.
Method dependency injection
Property dependency injection
Note: using property dependency injection is quite addictive.
Property parameter injection
You can also inject container parameters using @Value
annotation.
Pro-Tip: inject always scalar values, do not inject arrays. When you inject scalar values, their presence in container is validated during container compilation.
Autoscan
Autoscan was a feature of version 1.x of SkrzAutowiringBundle
. However, since Symfony 4.0, container supports
this feature
natively. Therefore, it was removed from the bundle and you should use resource
key to import directories of services.
Configuration
License
The MIT license. See LICENSE file.
All versions of autowiring-bundle with dependencies
doctrine/annotations Version ~1.5
symfony/config Version ~3.4|~4.0
symfony/dependency-injection Version ~4.0
symfony/http-kernel Version ~4.0