PHPackages                             mildabre/service-discovery - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mildabre/service-discovery

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mildabre/service-discovery
==========================

Attribute based service discovery for Nette DI.

v0.2.3(2mo ago)010↓66.7%1MITPHPPHP &gt;=8.1

Since Feb 14Pushed 2mo agoCompare

[ Source](https://github.com/mildabre/service-discovery)[ Packagist](https://packagist.org/packages/mildabre/service-discovery)[ RSS](/packages/mildabre-service-discovery/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (9)Used By (1)

Service Discovery
=================

[](#service-discovery)

[![Latest Stable Version](https://camo.githubusercontent.com/34e060c48bc32899764703d09eadbf049d7fa9583fbf5df231ca57cdb44d66ff/68747470733a2f2f706f7365722e707567782e6f72672f6d696c64616272652f736572766963652d646973636f766572792f762f737461626c65)](https://packagist.org/packages/mildabre/service-discovery)[![License](https://camo.githubusercontent.com/f503faec1b2ca62430c233cbd8c9dd784e4afcb4558807eca1884f34b1b60232/68747470733a2f2f706f7365722e707567782e6f72672f6d696c64616272652f736572766963652d646973636f766572792f6c6963656e7365)](https://packagist.org/packages/mildabre/service-discovery)

Attribute-based service discovery for Nette DI Container.

Simplify your application configuration by automatically discovering and registering services based on:

- Class type (parent class)
- PHP 8 attributes

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

[](#installation)

```
composer require mildabre/service-discovery
```

Bootstrap Hook
--------------

[](#bootstrap-hook)

Add this hook to your Nette `Bootstrap.php`:

```
use Mildabre\ServiceDiscovery\DI\ServiceDiscoveryExtension;

public function bootWebApplication(): Container
{
    $this->initializeEnvironment();
    ServiceDiscoveryExtension::boot($this->rootDir.'/temp');    # add just before $configurator->createContainer()
    return $this->configurator->createContainer();
}
```

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

[](#configuration)

Register the extension in your `common.neon` file:

```
extensions:
    discovery: Mildabre\ServiceDiscovery\DI\ServiceDiscoveryExtension
```

Service Discovery by Class Type
-------------------------------

[](#service-discovery-by-class-type)

Define discovery rules in your `service.neon`:

```
discovery:
    in:
        - %appDir%/Controls
        - %appDir%/Model

    type:
        - App\Controls\Abstract\AbstractControl
        - App\Model\Abstract\AbstractModel
```

All classes in `%appDir%/Controls` and `%appDir%/Model` matching these criteria will be automatically registered. Discovery by implementing interfaces is by design not possible.

Service Discovery by Attribute
------------------------------

[](#service-discovery-by-attribute)

```
use Mildabre\ServiceDiscovery\Attributes\Service;

#[Service]
class TokenManager
{}
```

Event Listener Discovery by Attribute
-------------------------------------

[](#event-listener-discovery-by-attribute)

Require [`mildabre/event-dispatcher`](https://github.com/mildabre/event-dispatcher). package.

```
use Mildabre\ServiceDiscovery\Attributes\EventListener;

#[EventListener]
class UserRegisteredListener
{
    public function handle(UserRegisteredEvent $event): void      #  handle event
    {}
}
```

Services with this attribute are automatically tagged with `event.listener` tag and added by `mildabre/event-dispatcher` to EventDispatcher.

Exclude Service from Discovery
------------------------------

[](#exclude-service-from-discovery)

```
use Mildabre\ServiceDiscovery\Attributes\Excluded;
use App\Model\Abstract\AbstractModel;

#[Excluded]                                     # overrides discovery by-type
class ShiftControl extends AbstractControl
{
    public function __construct(
        private readonly AbstractModel $model,
    )
    {}
}
```

Class excluded from auto-registration can still be instantiated manually via constructor, without relying on setter injection.

Important: Manually-registered services in services.neon are not affected by the attribute!

Lazy Services
-------------

[](#lazy-services)

Native PHP 8.4 lazy services are supported and can be enabled per discovery configuration:

```
discovery:
    lazy: true          # requires PHP 8.4+
```

When disabled, lazy initialization is not used and PHP 8.1+ is sufficient:

```
discovery:
    lazy: false         # PHP 8.1+
```

Individual services registered via `#[Service]` attribute can override the global lazy setting:

```
#[Service(lazy: false)]
class TokenManager
{}
```

Enable Inject mode by Class Type
--------------------------------

[](#enable-inject-mode-by-class-type)

```
discovery:
    in:
        - %appDir%/Controls
        - %appDir%/Model

    enableInject:
        - App\Controls\Abstract\AbstractControl
        - App\Model\Abstract\AbstractModel
```

Enable Inject mode by implementing interfaces is by design not possible.

Migration from Search Section
-----------------------------

[](#migration-from-search-section)

**Before:**

```
search:
    application:
        in: %appDir%
        implements: App\Core\Interfaces\AsService

    controls:
        in: '%appDir%/Controls'
        extends: App\Controls\Abstract\AbstractControl

decorator:
    App\Core\Interfaces\Injectable:
        inject: true
```

```
use App\Core\DI\AsService;
use App\Core\DI\Injectable;

class TokenService implements AsService
{}

class AbstractControl extends Control implements Injectable
{}
```

**After:**

```
discovery:
    in:
        - %appDir%

    type:
        - App\Controls\Abstract\AbstractControl

    enableInject:
        - App\Controls\Abstract\AbstractControl
```

```
use Mildabre\ServiceDiscovery\Attributes\Service;

#[Service]
class TokenService
{}
```

Go Event-Driven
---------------

[](#go-event-driven)

Service Discovery is a natural foundation for event-driven architecture. Pair it with `mildabre/event-dispatcher` - simple EventDispatcher that brings modern architecture possibilities.

- automatic listener discovery
- zero manual wiring
- clean separation of concerns

A worthy plugin for modern Nette-based applications.

[mildabre/event-dispatcher](https://github.com/mildabre/event-dispatcher)

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Nette DI 3.1+
- Nette Schema 1.2+
- Nette RobotLoader 4.0+

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) file.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance85

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~2 days

Total

8

Last Release

75d ago

PHP version history (2 changes)v0.1.0PHP &gt;=8.3

v0.1.1PHP &gt;=8.1

### Community

Maintainers

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

---

Top Contributors

[![mildabre](https://avatars.githubusercontent.com/u/34324008?v=4)](https://github.com/mildabre "mildabre (64 commits)")

---

Tags

nettediserviceservice discovery

### Embed Badge

![Health badge](/badges/mildabre-service-discovery/health.svg)

```
[![Health](https://phpackages.com/badges/mildabre-service-discovery/health.svg)](https://phpackages.com/packages/mildabre-service-discovery)
```

###  Alternatives

[nette/di

💎 Nette Dependency Injection Container: Flexible, compiled and full-featured DIC with perfectly usable autowiring and support for all new PHP features.

92340.6M1.4k](/packages/nette-di)[contributte/di

Extra contrib to nette/di

465.8M18](/packages/contributte-di)[contributte/event-dispatcher

Best event dispatcher / event manager / event emitter for Nette Framework

292.4M19](/packages/contributte-event-dispatcher)[contributte/menu-control

Menu control for Nette framework

29108.6k1](/packages/contributte-menu-control)[carrooi/nette-menu

Menu control for Nette framework

2950.0k1](/packages/carrooi-nette-menu)

PHPackages © 2026

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