PHPackages                             skrz/autowiring-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. skrz/autowiring-bundle

ActiveLibrary

skrz/autowiring-bundle
======================

Annotation-based autowiring for Symfony 4 dependency injection container

v2.0.0(8y ago)874.9k↓100%5[3 issues](https://github.com/skrz/autowiring-bundle/issues)[1 PRs](https://github.com/skrz/autowiring-bundle/pulls)MITPHPPHP ~7.1

Since May 25Pushed 6y ago2 watchersCompare

[ Source](https://github.com/skrz/autowiring-bundle)[ Packagist](https://packagist.org/packages/skrz/autowiring-bundle)[ RSS](/packages/skrz-autowiring-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (5)Versions (9)Used By (0)

Skrz\\Bundle\\AutowiringBundle
==============================

[](#skrzbundleautowiringbundle)

[![Build Status](https://camo.githubusercontent.com/c188e072202cb83e40704cc090f8b88c695ab09402d031ce91fc0e088c512b81/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f736b727a2f6175746f776972696e672d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/skrz/autowiring-bundle)[![Quality Score](https://camo.githubusercontent.com/0f341726b7cd2d3e3d12e3ba02ca57ed17db31fdf136c802fa9be7011d2ecc53/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f736b727a2f6175746f776972696e672d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/skrz/autowiring-bundle)[![Code Coverage](https://camo.githubusercontent.com/f9121e87a86f56b047c04cda49248e5cfd1c2c3ca60f915e744c6847bc2d1ba1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f736b727a2f6175746f776972696e672d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/skrz/autowiring-bundle)[![Downloads this Month](https://camo.githubusercontent.com/c6320255829fec518a9cb8b04a1eb5c1177a473adb598e3db6a2fc881c19bbb6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f736b727a2f6175746f776972696e672d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/skrz/autowiring-bundle)[![Latest stable](https://camo.githubusercontent.com/7b62faa36d29783137c9194bff23b13d2d7611da9d859d26d015d1e008725f7c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736b727a2f6175746f776972696e672d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/skrz/autowiring-bundle)

> Annotation-based autowiring for Symfony 4 dependency injection container

Installation
------------

[](#installation)

Add as [Composer](https://getcomposer.org/) dependency:

```
$ composer require skrz/autowiring-bundle
```

Then add `SkrzAutowiringBundle` to Symfony Kernel:

```
use Skrz\Bundle\AutowiringBundle\SkrzAutowiringBundle;

class AppKernel
{

    public function registerBundles()
    {
        return [
            ...
            new SkrzAutowiringBundle()
            ...
        ];
    }

}
```

Usage
-----

[](#usage)

Annotate your application components using `@Component` annotation and its subclasses, or so called "stereotypes". Predefined stereotypes are `@Controller`, `@Repository`, and `@Service`, e.g.:

```
use Skrz\Bundle\AutowiringBundle\Annotation\Controller;

/**
 * @Controller
 */
class HomepageController
{
    ...
}
```

Create your own application stereotypes by subclassing `@Component`.

### Constructor dependency injection

[](#constructor-dependency-injection)

```
// services.yml
services:
  Example\HomepageController: ~
```

```
namespace Example;

use Skrz\Bundle\AutowiringBundle\Annotation\Controller;

/**
 * @Controller
 */
class HomepageController
{

    /**
     * @var SomeService
     */
    private $someService;

    public function __construct(SomeService $someService)
    {
        $this->someService = $someService;
    }

    ...

}
```

`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:

```
// services.yml
services:
  Example\HomepageController:
    arguments:
      someParameter: %kernel.whatever%
```

```
namespace Example;

use Skrz\Bundle\AutowiringBundle\Annotation\Controller;

/**
 * @Controller
 */
class HomepageController
{

    /**
     * @var SomeService
     */
    private $someService;

    /**
     * @var string
     */
    private $someParameter;

    public function __construct(SomeService $someService, $someParameter)
    {
        $this->someService = $someService;
        $this->someParameter = $someParameter;
    }

    ...

}
```

The `$someService` argument is autowired and the `$someParameter` argument is injected depending on the configuration.

### Method dependency injection

[](#method-dependency-injection)

```
// services.yml

services:
  Example\HomepageController: ~
```

```
namespace Example;

use Skrz\Bundle\AutowiringBundle\Annotation\Controller;
use Skrz\Bundle\AutowiringBundle\Annotation\Autowired;

/**
 * @Controller
 */
class HomepageController
{

    /**
     * @var SomeService
     */
    private $someService;

    /**
     * @param SomeService $someService
     * @return void
     *
     * @Autowired
     */
    public function setSomeService(SomeService $someService)
    {
        $this->someService = $someService;
    }

    ...

}
```

### Property dependency injection

[](#property-dependency-injection)

```
// services.yml

services:
  Example\HomepageController: ~
```

```
namespace Example;

use Skrz\Bundle\AutowiringBundle\Annotation\Controller;
use Skrz\Bundle\AutowiringBundle\Annotation\Autowired;

/**
 * @Controller
 */
class HomepageController
{

    /**
     * @var SomeService
     *
     * @Autowired
     */
    public $someService;

    ...

}
```

Note: using property dependency injection is quite addictive.

### Property parameter injection

[](#property-parameter-injection)

You can also inject container parameters using `@Value` annotation.

```
// services.yml

services:
  Example\HomepageController: ~
```

```
namespace Example;

use Skrz\Bundle\AutowiringBundle\Annotation\Controller;
use Skrz\Bundle\AutowiringBundle\Annotation\Value;

/**
 * @Controller
 */
class HomepageController
{

    /**
     * @var string
     *
     * @Value("%kernel.root_dir%")
     */
    public $rootDir;

    ...

}
```

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)

Autoscan was a feature of version 1.x of `SkrzAutowiringBundle`. However, since Symfony 4.0, container supports [this feature](https://symfony.com/doc/current/service_container.html#importing-many-services-at-once-with-resource)natively. Therefore, it was removed from the bundle and you should use `resource` key to import directories of services.

```
// services.yml

services:
  Example\:
    resource: "../path/to/controllers/*Controller.php"
```

```
namespace Example;

use Skrz\Bundle\AutowiringBundle\Annotation\Controller;
use Skrz\Bundle\AutowiringBundle\Annotation\Autowired;

/**
 * @Controller
 */
class HomepageController
{

    /**
     * @var SomeService
     *
     * @Autowired
     */
    public $someService;

    ...

}
```

Configuration
-------------

[](#configuration)

```
# container extension key is "autowiring"
autowiring:

  # these service IDs won't be processed by autowiring
  ignored_services:
    # either specify exact service IDs
    - kernel
    - http_kernel

    # or use regular expressions (they must start with "/")
    - /^debug\./
    - /^file/

  # match interfaces to exact services
  preferred_services:
    Psr\Log\LoggerInterface: logger
    Monolog\Logger: logger
    Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface: session.storage.native

  # if you create your own stereotypes, you must add then here
  fast_annotation_checks: [ @Task, @Widget ]
```

License
-------

[](#license)

The MIT license. See [LICENSE](LICENSE) file.

###  Health Score

34

—

LowBetter than 79% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 53.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~167 days

Recently: every ~236 days

Total

7

Last Release

2950d ago

Major Versions

v1.3.0 → v2.0.02018-02-21

PHP version history (3 changes)v1.0.0PHP &gt;=5.4

v1.3.0PHP &gt;=5.5.9

v2.0.0PHP ~7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9a85a90ea8b2060137fbfb3baaf7604c0681d27022331e090fd42401d578880?d=identicon)[Skrz](/maintainers/Skrz)

---

Top Contributors

[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (17 commits)")[![jakubkulhan](https://avatars.githubusercontent.com/u/95001?v=4)](https://github.com/jakubkulhan "jakubkulhan (10 commits)")[![mzstic](https://avatars.githubusercontent.com/u/4610204?v=4)](https://github.com/mzstic "mzstic (3 commits)")[![klatys](https://avatars.githubusercontent.com/u/725081?v=4)](https://github.com/klatys "klatys (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/skrz-autowiring-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/skrz-autowiring-bundle/health.svg)](https://phpackages.com/packages/skrz-autowiring-bundle)
```

###  Alternatives

[mmoreram/gearman-bundle

Adds gearman support to your and Symfony4, Symfony5 project

236394.3k2](/packages/mmoreram-gearman-bundle)[handcraftedinthealps/rest-routing-bundle

This bundle provides automatic route registration for the Controllers

581.9M2](/packages/handcraftedinthealps-rest-routing-bundle)[thelia/thelia

Thelia is an ecommerce CMS.

8715.1k](/packages/thelia-thelia)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
