PHPackages                             pedhot-dev/nepotismfree-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. pedhot-dev/nepotismfree-di

ActiveLibrary[Framework](/categories/framework)

pedhot-dev/nepotismfree-di
==========================

A high-performance, opinionated, strict Dependency Injection Container for PHP 8.1+. No magic, no hidden wiring.

v1.1.0(5mo ago)0693MITPHPPHP ^8.1CI passing

Since Jan 20Pushed 5mo agoCompare

[ Source](https://github.com/Pedhot-Dev/NepotismFree-DI)[ Packagist](https://packagist.org/packages/pedhot-dev/nepotismfree-di)[ RSS](/packages/pedhot-dev-nepotismfree-di/feed)WikiDiscussions master Synced today

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

NepotismFree DI
===============

[](#nepotismfree-di)

**A High-Performance, Opinionated Dependency Injection Container for PHP 8.2+**

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/c9f64f714c636ba27a3bba6dfd52f98426832db1262747efa54b212d16943651/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d626c7565)](https://www.php.net/releases/8.2/en.php)

Philosophy
----------

[](#philosophy)

### What “NepotismFree” Means

[](#what-nepotismfree-means)

NepotismFree rejects architectural privilege.

No dependency is allowed into the system just because it is:

- nearby
- guessable
- convenient
- or “usually works”

Every dependency must earn its place by being:

- explicitly declared
- unambiguous
- verifiable
- and rejectable

If the container cannot prove correctness, it fails.

---

### Explicit Over Magic

[](#explicit-over-magic)

Most DI containers attempt to be helpful by guessing:

- which implementation to use
- which scalar value fits
- which fallback is “safe”

NepotismFree does none of this.

- Interfaces **never** resolve without bindings
- Scalars **never** resolve without explicit arguments
- Union / ambiguous types are rejected
- There are no silent defaults

If configuration is incomplete, the system fails fast.

---

### Fail Fast Is a Feature

[](#fail-fast-is-a-feature)

A system that fails loudly is honest.
A system that silently “works” is dangerous.

NepotismFree treats errors as **architectural signals**, not inconveniences.

Every failure:

- happens early
- explains the exact cause
- never masks another error

---

### No Service Locator. Ever.

[](#no-service-locator-ever)

Injecting the container is forbidden.

There is no global access. There is no runtime resolution escape hatch. There are no back doors.

If a service needs something, it must declare it explicitly in its constructor.

---

### Immutable by Design

[](#immutable-by-design)

The container lifecycle is strictly divided:

- **Builder phase** → configuration
- **Runtime phase** → resolution

Once built:

- no bindings can be added
- no lifecycles can be changed
- no tags can be modified

Mutation after build is a hard error.

---

📦 Example Usage
---------------

[](#-example-usage)

A complete, real-world example application is available in a separate repository:

👉 **[NepotismFree-DI Example – Notification System](https://github.com/Pedhot-Dev/NepotismFree-DI-Example)**

This example demonstrates:

- Proper constructor-based dependency injection
- Clean separation between Application, Domain, and Infrastructure layers
- Avoidance of service locator and closure-based wiring
- Honest adaptation to current container capabilities
- A realistic use case where DI is actually justified

The repository is intentionally kept small and focused, serving as a **canonical reference** for how this container is meant to be used in practice.

> Note:
> Some design choices (such as using a dedicated collection object) are deliberate trade-offs made to keep the application honest and aligned with the current DI container API.

---

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

[](#installation)

```
composer require pedhot-dev/nepotismfree-di
```

Usage
-----

[](#usage)

### Bootstrapping

[](#bootstrapping)

```
use PedhotDev\NepotismFree\Builder\ContainerBuilder;

$builder = new ContainerBuilder();

// 1. Interface Binding
$builder->bind(LoggerInterface::class, FileLogger::class);

// 2. Singleton Definition (Default are Prototypes if not specified)
$builder->singleton(DatabaseConnection::class);

// 3. Scalar/Argument Binding
$builder->bindArgument(FileLogger::class, 'logPath', '/var/log/app.log');

// 4. Contextual Binding (V2)
$builder->bindContext(LoggerInterface::class, SysLogger::class, Database::class);

// 5. Tagging (V2)
$builder->tag('events', AppEventHandler::class);

// 6. Modules (V2)
$builder->addModule(new AuthModule());

// 7. Factory Binding (for complex construction)
$builder->bind(MailerInterface::class, function (ContainerInterface $c) {
    return new SmtpMailer($c->get(Config::class)->get('smtp'));
});

// Build and validate
$builder->validate();
$container = $builder->build();
```

### Resolution

[](#resolution)

```
$logger = $container->get(LoggerInterface::class);

// Resolving tagged services
$handlers = $container->getTagged('events');
foreach ($handlers as $handler) {
    $handler->handle();
}
```

Advanced Features
-----------------

[](#advanced-features)

- **Compilation**: Lock your container for production by calling `$builder->compile($path)`.
- **Strict Modules**: Encapsulate logic. Only "exposed" services can be accessed from outside the module.
- **Fail-Fast Validation**: Call `$builder->validate()` to analyze the whole graph before the first service is ever resolved.

Non-Goals
---------

[](#non-goals)

- **Service Location:** We do not encourage passing the container around.
- **Auto-Discovery:** We do not scan your filesystem for classes.
- **YAML/XML Config:** pure PHP configuration only.

When NOT to use this
--------------------

[](#when-not-to-use-this)

- If you want "rapid prototyping" where everything "just works" without config.
- If you rely heavily on "Autowiring" of scalar values by name guessing.
- If you need to mutate the container at runtime (e.g., during tests).

License
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance71

Regular maintenance activity

Popularity8

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% 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 ~1 days

Total

2

Last Release

164d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2605cface9339b0534b6be9f1bff3082e5608e44dc0969725a58309536ab496a?d=identicon)[AgusPedhot](/maintainers/AgusPedhot)

---

Top Contributors

[![Pedhot-Dev](https://avatars.githubusercontent.com/u/70968506?v=4)](https://github.com/Pedhot-Dev "Pedhot-Dev (6 commits)")[![poggit-bot](https://avatars.githubusercontent.com/u/22427965?v=4)](https://github.com/poggit-bot "poggit-bot (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pedhot-dev-nepotismfree-di/health.svg)

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

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M297](/packages/laravel-dusk)[nineinchnick/edatatables

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

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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