PHPackages                             jbuncle/simple-dic - 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. jbuncle/simple-dic

ActiveLibrary

jbuncle/simple-dic
==================

Simple Dependency Injection container focussing on auto injection.

7.0.1(4y ago)051PHPPHP &gt;=7.1CI passing

Since Jul 28Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/jbuncle/simple-dic)[ Packagist](https://packagist.org/packages/jbuncle/simple-dic)[ RSS](/packages/jbuncle-simple-dic/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

PHP Simple DIC
==============

[](#php-simple-dic)

A simple dependency injection container with focus on automatic wiring (auto-wiring) dependencies.

Introduction
------------

[](#introduction)

Simple DIC is implemented with auto-wiring at the forefront.

This basically means that if a class can be created by automatically by recursively resolving dependencies then you will get a class back, even if you haven't manually put anything into the container!

For this to happen fully 100% automatically, all class constructor argumentss will need to have explicit type hints for instantiable types (i.e. they need to be non-abstract, non-interface, non-native).

If the types required are using interfaces and/or abstract classes then you can define a type mapping with the `addTypeMapping` method, to tell the container what concrete classes to resolve the types to.

If the types required have dependencies on native types (e.g. the constructor requires a string), then you can define factory methods to create the instance manually. You're factory method can define arguments which will also be autowired.

I have tried to optimise this implementation as much as possible.

**Example**

In the example below we are able to get an instance of the `Foo` class, simply be asking the container for one, no setup of the container is required other than instantiating it.

```
class Baz {

    public __construct();
}

class Bar {

    public __construct(Baz baz);
}

class Foo {

    public __construct(Bar bar);
}

$container = new \JBuncle\SimpleDic\Container();
$fooInstance = $container->getInstance(Foo::class);
```

This will automatically instantiate instances of `Foo`, `Bar` and `Baz`, and store those instances in the container automatically. Therefore subsequently calling `$container->getInstance(Bar::class)` will give you the same class instance used to create `Foo`.

Adding Factory Functions
------------------------

[](#adding-factory-functions)

Factory functions allow you define a callback to use to manually create instances (lazily) when needed.

Useful for instances that cannot be created using full automatic autowiring.

Type Mapping
------------

[](#type-mapping)

Type mapping allows you to tell the container what type to use when a specific type is requested.

This is useful for when you want to define what concrete or extending class to use when a supertype or interface is required.

PSR Compatibility
-----------------

[](#psr-compatibility)

A simple DIC can be easily converted into a PHP FIG PSR-11 (`psr/container` v2) compatible implementation using the `PsrAdapter` wrapper class:

```
$containerFactory = new \JBuncle\SimpleDic\ContainerFactory();
$container = $containerFactory->create();

/* @var $psrContainer \Psr\Container\ContainerInterface */
$psrContainer = new \JBuncle\SimpleDic\PsrAdapter($container);
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance59

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Total

2

Last Release

1551d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7d2b61c26f3cae0b6e0b8c9e07555b189fe71e5b141e5e1a8129acaace3f674d?d=identicon)[jbuncle](/maintainers/jbuncle)

---

Top Contributors

[![jbuncle](https://avatars.githubusercontent.com/u/11473689?v=4)](https://github.com/jbuncle "jbuncle (45 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jbuncle-simple-dic/health.svg)

```
[![Health](https://phpackages.com/badges/jbuncle-simple-dic/health.svg)](https://phpackages.com/packages/jbuncle-simple-dic)
```

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[api-platform/state

API Platform state interfaces

223.4M57](/packages/api-platform-state)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)[symfony/json-streamer

Provides powerful methods to read/write data structures from/into JSON streams.

14440.0k8](/packages/symfony-json-streamer)[rubix/server

Deploy your Rubix ML models to production with scalable stand-alone inference servers.

632.3k](/packages/rubix-server)

PHPackages © 2026

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