PHPackages                             felixgro/fgdi - 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. felixgro/fgdi

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

felixgro/fgdi
=============

Minimal Dependency Injection Container

1.3.4(7mo ago)098MITPHPPHP ^8.0

Since Jul 11Pushed 7mo agoCompare

[ Source](https://github.com/felixgro/php-di-container)[ Packagist](https://packagist.org/packages/felixgro/fgdi)[ RSS](/packages/felixgro-fgdi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (8)Used By (0)

Modern Dependency Injection Container for PHP
=============================================

[](#modern-dependency-injection-container-for-php)

A simple and lightweight Dependency Injection Container for PHP, compliant with PSR-11.

Features
--------

[](#features)

- **PSR-11 Compliance**: Fully compliant with the PSR-11 Container Interface.
- **Type Safety**: Strong type hints for better code quality and maintainability.
- **Automatic Resolution**: Automatically resolves dependencies based on type hints.
- **Singleton Support**: Easily register and retrieve singleton services.
- **Fully Tested**: Using [PestPHP](https://pestphp.com/).

Getting Started
---------------

[](#getting-started)

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

[](#requirements)

- PHP 8.0 or higher
- Composer

### Installation

[](#installation)

```
composer require felixgro/fgdi
```

### Basic Usage

[](#basic-usage)

```
use FGDI\Container;

// Create a container instance. This should be done once in your application.
$container = new Container();

// Register a value of any type directly in the container
$container->set('foo', 'bar');
$value = $container->get('foo'); // returns 'bar'

$container->set('baz', 42);
$value = $container->get('baz'); // returns 42

$container->set('nestedStuff', [
    'complex' => ['nested' => 'stuff'],
]);
$value = $container->get('nestedStuff'); // you guess it!

// Register classes automatically and resolve all nested dependencies needed
$container->set(AuthService::class);
$authService = $container->get(AuthService::class);

// If you want more control over the instantiation, you can pass a factory callback which returns an instanciated service
$container->set(CustomService::class, function (Container $container) {
    return new CustomService($container->get(NestedService::class));
});

// Conveniently register a singleton service
$container->singleton(DatabaseConnection::class);
$db1 = $container->get(DatabaseConnection::class);
$db2 = $container->get(DatabaseConnection::class);
// $db1 and $db2 are the exact same instance

// Check if a service is registered in the container.
$hasDC = $container->has(DatabaseConnection::class);
// This even returns true if the service is not yet registered but instantiable by the container
```

Development
-----------

[](#development)

### Requirements

[](#requirements-1)

- PHP 8.0 or higher
- Composer

### Installation

[](#installation-1)

Run the following command to install the dependencies:

```
composer install
```

### Running Tests

[](#running-tests)

Run the following command to execute the tests:

```
composer test
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance65

Regular maintenance activity

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

Recently: every ~6 days

Total

7

Last Release

214d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c0ee3b23446e3a814a20a600194953aacb57b6bd5a58c4e93224158a986a972?d=identicon)[felgro](/maintainers/felgro)

---

Top Contributors

[![felixgro](https://avatars.githubusercontent.com/u/53900040?v=4)](https://github.com/felixgro "felixgro (19 commits)")

---

Tags

containerdependency-injectiondiservice provider

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/felixgro-fgdi/health.svg)

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[aura/di

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

356968.3k58](/packages/aura-di)[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3611.7M3](/packages/mrclay-props-dic)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)

PHPackages © 2026

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