PHPackages                             thesis/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. thesis/di

ActiveLibrary[Framework](/categories/framework)

thesis/di
=========

Thesis DI Container

0.5.3(1mo ago)170MITPHPPHP ^8.4.12CI failing

Since Feb 8Pushed 1w ago1 watchersCompare

[ Source](https://github.com/thesis-php/dic)[ Packagist](https://packagist.org/packages/thesis/di)[ Fund](https://www.tinkoff.ru/cf/5MqZQas2dk7)[ RSS](/packages/thesis-di/feed)WikiDiscussions 0.5.x Synced 1w ago

READMEChangelog (10)Dependencies (27)Versions (16)Used By (0)

Thesis Dic
==========

[](#thesis-dic)

A fresh take on the PHP dependency injection container, with all the features you expect.

- **Modular** — isolated or shared config scope per module
- **Type-safe** with local reasoning
- **Autowiring** at the module level
- **Autoconfiguration** — plug in your attributes or autoconfigure by type
- **Tags** with flexible resolution
- **Lifetimes** — singleton / canBeScoped / scoped
- **Callable** services — functions and methods as first-class services
- **Variadic parameters** supported

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

[](#requirements)

- PHP 8.4.12+

Contents
--------

[](#contents)

- [Installation](#installation)
- [Quick start](#quick-start)
- [Documentation](#documentation)

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

[](#installation)

```
composer require thesis/dic
```

Quick start
-----------

[](#quick-start)

> This guide covers only a fraction of what Dic can do — just enough to get you started.

### Dic

[](#dic)

The [`Thesis\Dic`](src/Dic.php) class is the heart of container configuration. It lets you declare services, require modules, subscribe to events and more.

### Module

[](#module)

A module is the unit of composition: you compose your application from modules, and the application itself is just the root module.

A module is a class implementing [`Thesis\Dic\Module`](src/Dic/Module.php): it receives a `Dic`, declares services, and returns whatever it exports — usually a `Ref`.

### Ref

[](#ref)

No string identifiers to invent — they aren't type-safe. Instead, declaring a service returns a [`Thesis\Dic\Ref`](src/Dic/Ref.php), its handle and identifier, with `T` inferred from configuration:

```
$logger = $dic->object(NullLogger::class); // Ref
```

A ref *is* the service's identity: a distinct ref is a distinct service. Assign it to a variable and pass it around to inject, import or export.

### Declaring services

[](#declaring-services)

Use `object()` to declare an object service, and `arg()` to override individual constructor arguments:

```
use Psr\Log\NullLogger;
use Thesis\Dic;
use Thesis\Dic\Module;

final readonly class ConsoleModule implements Module
{
    public function configure(Dic $dic)
    {
        $logger = $dic->object(NullLogger::class);

        $dic
            ->object(ConsoleApplication::class)
            ->arg('logger', $logger);
    }
}
```

The `$logger` ref is passed as a constructor argument — that's how services get wired together. See [Arguments](docs/arguments.md) for named, positional and variadic arguments.

### Putting it all together

[](#putting-it-all-together)

A module can depend on services it doesn't declare itself: accept them as constructor arguments and wire them in.

```
use Psr\Log\LoggerInterface;
use Thesis\Dic;
use Thesis\Dic\Module;
use Thesis\Dic\Ref;

/**
 * @implements Module
 */
final readonly class ConsoleModule implements Module
{
    /**
     * @param Ref $logger
     */
    public function __construct(
        private Ref $logger,
    ) {}

    public function configure(Dic $dic): mixed
    {
        return $dic
            ->object(ConsoleApplication::class)
            ->arg('logger', $this->logger);
    }
}
```

To use a module inside another one, call `import()` and get whatever that module exports. See [Modularity](docs/modularity.md) for how `import()` isolates modules and when to use `apply()` instead.

```
use Psr\Log\NullLogger;
use Thesis\Dic;
use Thesis\Dic\Module;
use Thesis\Dic\Ref;

/**
 * @implements Module
 */
final readonly class MyApp implements Module
{
    public function configure(Dic $dic): mixed
    {
        $logger = $dic->object(NullLogger::class);

        return $dic->import(new ConsoleModule($logger));
    }
}
```

To run an application, pass the root module to `Dic::run()` together with `$main` — a function that receives the resolved service. The container builds, calls `$main`, and disposes everything afterwards — even on failure:

```
use Thesis\Dic;

$status = Dic::run(
    module: new MyApp(),
    main: static fn (ConsoleApplication $cli) => $cli->run(),
);

exit($status);
```

For tests and debugging, `Dic::build()` returns the resolved module's export without disposing anything:

```
use Testo\Assert;
use Thesis\Dic;

$cli = Dic::build(new MyApp());

Assert::instanceOf($cli, ConsoleApplication::class);
```

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

[](#documentation)

- [Objects](docs/object.md) — declaring object services, factories, post-construction calls, lazy instantiation
- [Values](docs/value.md) — declaring ready-made values and refs as services
- [Functions and closures](docs/closure.md) — type-safe callable services, runtime parameters and dependencies
- [Arguments](docs/arguments.md) — named, positional and variadic arguments
- [Autowiring](docs/autowiring.md) — binding services to types and qualifiers
- [Tags](docs/tags.md) — tagging, collecting tagged services, tag resolution and autoconfiguration
- [Modularity](docs/modularity.md) — `Module` interface, `import()` and `apply()`
- [Lifetimes](docs/lifetime.md) — singleton, scoped and canBeScoped lifetimes, and the `Scoped` handle
- [Disposal](docs/disposal.md) — releasing resources when a scope or the container is disposed

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance96

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Recently: every ~2 days

Total

16

Last Release

41d ago

PHP version history (2 changes)0.1.0PHP ^8.4

0.5.1PHP ^8.4.12

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2552865?v=4)[Valentin Udaltsov](/maintainers/vudaltsov)[@vudaltsov](https://github.com/vudaltsov)

---

Top Contributors

[![vudaltsov](https://avatars.githubusercontent.com/u/2552865?v=4)](https://github.com/vudaltsov "vudaltsov (135 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.9k556.2M21.5k](/packages/laravel-framework)[symfony/symfony

The Symfony PHP framework

31.4k87.4M2.2k](/packages/symfony-symfony)[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k257.3M12.4k](/packages/symfony-framework-bundle)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19467.3M1.9k](/packages/drupal-core)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[illuminate/database

The Illuminate Database package.

2.8k55.8M13.1k](/packages/illuminate-database)

PHPackages © 2026

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