PHPackages                             dotkernel/dot-annotated-services - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. dotkernel/dot-annotated-services

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

dotkernel/dot-annotated-services
================================

Dotkernel service creation component through laminas-servicemanager and annotations

5.2.0(1y ago)812.8k↑325%3[2 issues](https://github.com/dotkernel/dot-annotated-services/issues)1MITPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0CI failing

Since Mar 7Pushed 7mo ago2 watchersCompare

[ Source](https://github.com/dotkernel/dot-annotated-services)[ Packagist](https://packagist.org/packages/dotkernel/dot-annotated-services)[ Docs](https://github.com/dotkernel/dot-annotated-services)[ RSS](/packages/dotkernel-dot-annotated-services/feed)WikiDiscussions 4.0 Synced 3w ago

READMEChangelog (10)Dependencies (5)Versions (31)Used By (1)

dot-annotated-services
======================

[](#dot-annotated-services)

Dotkernel component used to create services through [Laminas Service Manager](https://github.com/laminas/laminas-servicemanager) and inject them with dependencies just using method annotations. It can also create services without the need to write factories. Annotation parsing can be cached to improve performance.

This package can clean up your code by getting rid of all the factories you write, sometimes just to inject a dependency or two.

Documentation
-------------

[](#documentation)

Documentation is available at: .

Version History
---------------

[](#version-history)

BranchPSR-11Docblock CommentsOSS LifecyclePHP Version5.01 || 2Attributes[![OSS Lifecycle](https://camo.githubusercontent.com/2dee43543ffd081cf771acaffa298eb87c3e762ef24b9688d1796a793b899844/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c653f66696c655f75726c3d68747470732533412532462532466769746875622e636f6d253246646f746b65726e656c253246646f742d616e6e6f74617465642d7365727669636573253246626c6f62253246352e302532464f53534d45544144415441)](https://camo.githubusercontent.com/2dee43543ffd081cf771acaffa298eb87c3e762ef24b9688d1796a793b899844/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c653f66696c655f75726c3d68747470732533412532462532466769746875622e636f6d253246646f746b65726e656c253246646f742d616e6e6f74617465642d7365727669636573253246626c6f62253246352e302532464f53534d45544144415441)[![PHP from Packagist (specify version)](https://camo.githubusercontent.com/c07c67d6e97293346dbd21d3401080a7b3e8b1b6f4aae1a5c2f9ab32672a4a41/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d616e6e6f74617465642d73657276696365732f352e322e30)](https://camo.githubusercontent.com/c07c67d6e97293346dbd21d3401080a7b3e8b1b6f4aae1a5c2f9ab32672a4a41/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d616e6e6f74617465642d73657276696365732f352e322e30)4.01Annotations[![OSS Lifecycle](https://camo.githubusercontent.com/72ea23cd504c11345f996f0eea957d8c130eb1af0d1f3cea8e926430ea4400e1/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c653f66696c655f75726c3d68747470732533412532462532466769746875622e636f6d253246646f746b65726e656c253246646f742d616e6e6f74617465642d7365727669636573253246626c6f62253246342e302532464f53534d45544144415441)](https://camo.githubusercontent.com/72ea23cd504c11345f996f0eea957d8c130eb1af0d1f3cea8e926430ea4400e1/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c653f66696c655f75726c3d68747470732533412532462532466769746875622e636f6d253246646f746b65726e656c253246646f742d616e6e6f74617465642d7365727669636573253246626c6f62253246342e302532464f53534d45544144415441)[![PHP from Packagist (specify version)](https://camo.githubusercontent.com/94e63f9c11b28c8796b3cfbf3b6aa3d74da59bab48e384bf805dbdaa7ff21ebd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d616e6e6f74617465642d73657276696365732f342e342e30)](https://camo.githubusercontent.com/94e63f9c11b28c8796b3cfbf3b6aa3d74da59bab48e384bf805dbdaa7ff21ebd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d616e6e6f74617465642d73657276696365732f342e342e30)3.01Annotations[![OSS Lifecycle](https://camo.githubusercontent.com/3cb487d046288e1577a925f14ccab1ca161dee528ed1b2b35551793f34f15157/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c653f66696c655f75726c3d68747470732533412532462532466769746875622e636f6d253246646f746b65726e656c253246646f742d616e6e6f74617465642d7365727669636573253246626c6f62253246332e302532464f53534d45544144415441)](https://camo.githubusercontent.com/3cb487d046288e1577a925f14ccab1ca161dee528ed1b2b35551793f34f15157/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c653f66696c655f75726c3d68747470732533412532462532466769746875622e636f6d253246646f746b65726e656c253246646f742d616e6e6f74617465642d7365727669636573253246626c6f62253246332e302532464f53534d45544144415441)[![PHP from Packagist (specify version)](https://camo.githubusercontent.com/3ba7cba35fef2dddf20e9394306659737741fb84586ad6b3f71b0172e876fa1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d616e6e6f74617465642d73657276696365732f332e322e31)](https://camo.githubusercontent.com/3ba7cba35fef2dddf20e9394306659737741fb84586ad6b3f71b0172e876fa1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d616e6e6f74617465642d73657276696365732f332e322e31)Badges
------

[](#badges)

[![OSS Lifecycle](https://camo.githubusercontent.com/72ea23cd504c11345f996f0eea957d8c130eb1af0d1f3cea8e926430ea4400e1/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c653f66696c655f75726c3d68747470732533412532462532466769746875622e636f6d253246646f746b65726e656c253246646f742d616e6e6f74617465642d7365727669636573253246626c6f62253246342e302532464f53534d45544144415441)](https://camo.githubusercontent.com/72ea23cd504c11345f996f0eea957d8c130eb1af0d1f3cea8e926430ea4400e1/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c653f66696c655f75726c3d68747470732533412532462532466769746875622e636f6d253246646f746b65726e656c253246646f742d616e6e6f74617465642d7365727669636573253246626c6f62253246342e302532464f53534d45544144415441)[![PHP from Packagist (specify version)](https://camo.githubusercontent.com/94e63f9c11b28c8796b3cfbf3b6aa3d74da59bab48e384bf805dbdaa7ff21ebd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d616e6e6f74617465642d73657276696365732f342e342e30)](https://camo.githubusercontent.com/94e63f9c11b28c8796b3cfbf3b6aa3d74da59bab48e384bf805dbdaa7ff21ebd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d616e6e6f74617465642d73657276696365732f342e342e30)

[![GitHub issues](https://camo.githubusercontent.com/085cd4e2f89e529220a20f90a61097ad2ecafa6f1f6c9929e0ad4d3ffc1c6577/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f646f746b65726e656c2f646f742d616e6e6f74617465642d7365727669636573)](https://github.com/dotkernel/dot-annotated-services/issues)[![GitHub forks](https://camo.githubusercontent.com/b7942949242dcaeb4230bc67203909948c54253ee35e7a21c045570bee4b0127/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f646f746b65726e656c2f646f742d616e6e6f74617465642d7365727669636573)](https://github.com/dotkernel/dot-annotated-services/network)[![GitHub stars](https://camo.githubusercontent.com/6f8813764a7349a37ab3b397d7e00af19229d781885a7be8cc100f93ff621d33/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f646f746b65726e656c2f646f742d616e6e6f74617465642d7365727669636573)](https://github.com/dotkernel/dot-annotated-services/stargazers)[![GitHub license](https://camo.githubusercontent.com/3e49c14dc0bced5cc043353d4564fbf2bce4414ddaf969fb16c5da2305196189/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f646f746b65726e656c2f646f742d616e6e6f74617465642d7365727669636573)](https://github.com/dotkernel/dot-annotated-services/blob/4.0/LICENSE.md)

[![Build Static](https://github.com/dotkernel/dot-annotated-services/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-annotated-services/actions/workflows/continuous-integration.yml)[![codecov](https://camo.githubusercontent.com/35d35713903ef626e5fa8640f6afbccffda6cca52095d7143d690d8cdb737447/68747470733a2f2f636f6465636f762e696f2f67682f646f746b65726e656c2f646f742d616e6e6f74617465642d73657276696365732f67726170682f62616467652e7376673f746f6b656e3d5a425a444541334c5938)](https://codecov.io/gh/dotkernel/dot-annotated-services)[![PHPStan](https://github.com/dotkernel/dot-annotated-services/actions/workflows/static-analysis.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-annotated-services/actions/workflows/static-analysis.yml)

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

[](#installation)

Run the following command in your project directory

```
composer require dotkernel/dot-annotated-services
```

After installing, add the `ConfigProvider` class to your configuration aggregate.

Usage
-----

[](#usage)

### Using the AnnotatedServiceFactory

[](#using-the-annotatedservicefactory)

You can register services in the service manager using the `AnnotatedServiceFactory` as below.

```
return [
    'factories' => [
        ServiceClass::class => AnnotatedServiceFactory::class,
    ],
];
```

> You can use only the fully qualified class name as the service key.

The next step is to annotate the service constructor or setters with the service names to inject.

```
use Dot\AnnotatedServices\Annotation\Inject;

/**
 * @Inject({
 *     Dependency1::class,
 *     Dependency2::class,
 *     "config"
 * })
 */
public function __construct(
    protected Dependency1 $dep1,
    protected Dependency2 $dep2,
    protected array $config
) {
}
```

The annotation `@Inject` is telling the factory to inject the services between curly braces. Valid service names should be provided, as registered in the service manager.

To inject an array value from the service manager, you can use dot notation as below.

```
use Dot\AnnotatedServices\Annotation\Inject;

/**
 * @Inject({"config.debug"})
 */
```

which will inject `$container->get('config')['debug'];`

> Even if using dot annotation, the annotated factory will check first if a service name exists with that name.

You can use the `@Inject` annotation on setters too, they will be called at creation time and injected with the configured dependencies.

### Using the AnnotatedRepositoryFactory

[](#using-the-annotatedrepositoryfactory)

You can register doctrine repositories and inject them using the AnnotatedRepositoryFactory as below.

```
return [
    'factories' => [
        ExampleRepository::class => AnnotatedRepositoryFactory::class,
    ],
];
```

The next step is to add the `@Entity` annotation in the repository class.

The `name` field has to be the fully qualified class name.

Every repository should extend `Doctrine\ORM\EntityRepository`.

```
use Doctrine\ORM\EntityRepository;
use Dot\AnnotatedServices\Annotation\Entity;

/**
 * @Entity(name="App\Entity\Example")
 */
class ExampleRepository extends EntityRepository
{
}
```

### Using the abstract factory

[](#using-the-abstract-factory)

Using this approach, no service manager configuration is required. It uses the registered abstract factory to create annotated services.

To tell the abstract factory which services are to be created, you need to annotate the service class with the `@Service` annotation.

```
use Dot\AnnotatedServices\Annotation\Service;

/*
 * @Service
 */
class ServiceClass
{
    // configure injections as described in the previous section
}
```

And that's it, you don't need to configure the service manager with this class, creation will happen automatically.

Cache annotations
-----------------

[](#cache-annotations)

This package is built on top of `doctrine/annotation` and `doctrine/cache`. To cache annotations, you should register a service factory at key `AbstractAnnotatedFactory::CACHE_SERVICE` that should return a valid `Doctrine\Common\Cache\Cache` cache driver. See [Cache Drivers](https://github.com/doctrine/cache/tree/master/lib/Doctrine/Common/Cache) for available implementations offered by doctrine.

Below, we give an example, as defined in our frontend and admin starter applications:

```
return [
    'annotations_cache_dir' => __DIR__ . '/../../data/cache/annotations',
    'dependencies' => [
        'factories' => [
            // used by dot-annotated-services to cache annotations
            // needs to return a cache instance from Doctrine\Common\Cache
            AbstractAnnotatedFactory::CACHE_SERVICE => AnnotationsCacheFactory::class,
        ]
    ],
];
```

```
namespace Frontend\App\Factory;

use Doctrine\Common\Cache\FilesystemCache;
use Psr\Container\ContainerInterface;

class AnnotationsCacheFactory
{
    public function __invoke(ContainerInterface $container)
    {
        //change this to suite your caching needs
        return new FilesystemCache($container->get('config')['annotations_cache_dir']);
    }
}
```

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance46

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~106 days

Recently: every ~64 days

Total

31

Last Release

221d ago

Major Versions

v1.1.1 → 2.0.x-dev2020-01-30

v2.0.0 → v3.02020-04-12

3.2.1 → 4.0.02022-09-19

4.1.7 → 5.0.02024-03-08

4.4.0 → 5.0.x-dev2025-11-14

PHP version history (9 changes)1.0.0PHP ^7.1

2.0.x-devPHP ^7.2

v3.0PHP ^7.4

3.2.0PHP ~7.4.0 || ~8.0.0 || ~8.1.0

4.1.0PHP ~8.1.0 || ~8.2.0

4.1.4PHP ~8.1.0 || ~8.2.0 || ~8.3.0

5.0.0PHP ~8.2.0 || ~8.3.0

5.2.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0

4.4.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1156873?v=4)[Dotkernel](/maintainers/dotkernel)[@dotkernel](https://github.com/dotkernel)

---

Top Contributors

[![n3vrax](https://avatars.githubusercontent.com/u/5805542?v=4)](https://github.com/n3vrax "n3vrax (24 commits)")[![alexmerlin](https://avatars.githubusercontent.com/u/4542449?v=4)](https://github.com/alexmerlin "alexmerlin (20 commits)")[![arhimede](https://avatars.githubusercontent.com/u/22009710?v=4)](https://github.com/arhimede "arhimede (13 commits)")[![bidi47](https://avatars.githubusercontent.com/u/27284979?v=4)](https://github.com/bidi47 "bidi47 (12 commits)")[![marioradu05](https://avatars.githubusercontent.com/u/10761919?v=4)](https://github.com/marioradu05 "marioradu05 (8 commits)")[![Howriq](https://avatars.githubusercontent.com/u/63609103?v=4)](https://github.com/Howriq "Howriq (4 commits)")[![gabidj](https://avatars.githubusercontent.com/u/3998573?v=4)](https://github.com/gabidj "gabidj (2 commits)")

---

Tags

containerfactorydependencydiserviceinjectattribute

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dotkernel-dot-annotated-services/health.svg)

```
[![Health](https://phpackages.com/badges/dotkernel-dot-annotated-services/health.svg)](https://phpackages.com/packages/dotkernel-dot-annotated-services)
```

###  Alternatives

[league/container

A fast and intuitive dependency injection container.

86792.2M396](/packages/league-container)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2859.2k2](/packages/capsule-di)[miladrahimi/phpcontainer

Dependency injection (IoC) container for PHP projects

1323.5k2](/packages/miladrahimi-phpcontainer)

PHPackages © 2026

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