PHPackages                             genai/di - 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. [Framework](/categories/framework)
4. /
5. genai/di

ActiveLibrary[Framework](/categories/framework)

genai/di
========

Popular DI attributes (#\[Service\], #\[Repository\], #\[Configuration\], #\[Bean\], #\[Value\]) and their processor, targeting GenAI\\Container. Build-time (PHP 8).

v1.0.1(1mo ago)0161↓29.2%Apache-2.0PHPPHP &gt;=8.0CI passing

Since Jul 3Pushed 1mo agoCompare

[ Source](https://github.com/GenAIIO/php-di)[ Packagist](https://packagist.org/packages/genai/di)[ RSS](/packages/genai-di/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

genai/di
========

[](#genaidi)

Popular dependency-injection attributes and the processor that compiles them into a `genai/container` definition file.

This is a **build-time** package (PHP 8): it's read by the `genai/attribute`scanner during compilation. The container file it produces is **PHP 5.3-safe**, like everything `genai/container` emits.

Attributes
----------

[](#attributes)

AttributeTargetEffect`#[Service]`classregister the class as an autowired bean`#[Repository]`classsame — a stereotype for the persistence layer`#[Configuration]`classregister the class as a bean; its `#[Bean]` methods become factory beans`#[Bean]`methoda bean produced by calling the method on its (configuration) bean`#[Value]`parameterinject a value into a constructor / factory parameter`Service`/`Repository`/`Configuration` all extend `Component`; one `ComponentProcessor` handles them via `ReflectionAttribute::IS_INSTANCEOF`.

Usage
-----

[](#usage)

Point the scanner at your app plus this processor's namespace; it auto-registers `ComponentProcessor` (by type) and dumps `container.php`:

```
$scanner = new GenAI\Attribute\Scanner($loader);
$scanner->scan(['App', 'GenAI\\Di\\Processor']);
$scanner->compile(new GenAI\Attribute\Context($configDir, $outputDir, $parameters));
```

```
#[Service]
class UserController {
    public function __construct(UserRepository $repo) {}   // autowired by type
}

#[Repository]
class UserRepository {}

#[Configuration]
class AppConfig {
    #[Bean(Mailer::class)]
    public function mailer(Clock $clock) {                 // params autowired too
        return new Mailer($clock);
    }
}
```

`#[Value]` forms
----------------

[](#value-forms)

```
#[Value('${app.name}')]   // a config value — looked up in Context::$parameters and BAKED at build
#[Value('%db.dsn%')]      // a runtime container parameter -> $c->get('db.dsn')
#[Value('sendmail')]      // a literal
```

`${...}` is resolved at compile time from the flat `parameters` map you pass to `Context` (you populate it from your config source). A missing key fails the build with a clear error.

`#[Bean]` id + the PHP 5.3 caveat
---------------------------------

[](#bean-id--the-php-53-caveat)

A `#[Bean]` method's id is, in order: the explicit `#[Bean('id')]` / `#[Bean(Type::class)]`, else the method's return type, else the method name.

A `#[Bean]` method is **called at runtime** (on the configuration bean). If your runtime is **PHP 5.3** it must not declare a `: ReturnType` (return types are PHP 7+), so give the id explicitly:

```
#[Bean(Renderer::class)]      // the attribute line is a comment on 5.3 — Type::class there is fine
public function renderer() {  // no ': Renderer'
    return new Renderer(__DIR__ . '/../templates');
}
```

On a PHP 7+/8 runtime you can use the return type and drop the explicit id.

Requires
--------

[](#requires)

`php >=8.0`, `genai/attribute`, `genai/container` (it bridges the two; the runtime container it feeds stays PHP 5.3).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance90

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

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

Total

2

Last Release

47d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/25e5bd31b5dd70d47cbdc738bded06dbabfba3d584acce63c2c4b4fb7847f39d?d=identicon)[jinnguyen](/maintainers/jinnguyen)

---

Top Contributors

[![linhnnmt](https://avatars.githubusercontent.com/u/162856460?v=4)](https://github.com/linhnnmt "linhnnmt (7 commits)")

### Embed Badge

![Health badge](/badges/genai-di/health.svg)

```
[![Health](https://phpackages.com/badges/genai-di/health.svg)](https://phpackages.com/packages/genai-di)
```

###  Alternatives

[awcodes/filament-addons

A set of components / fields to extend Filament Admin.

3013.1k2](/packages/awcodes-filament-addons)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)

PHPackages © 2026

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