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

ActiveLibrary[Framework](/categories/framework)

ice-cream/di
============

ice-cream di (Dependency Injection) is my own take on DI, to keep it simple and easy to use.

1.2.1(8y ago)122MITPHPPHP &gt;=7.2.0

Since Aug 13Pushed 8y agoCompare

[ Source](https://github.com/AdamKyle/ice-cream-di)[ Packagist](https://packagist.org/packages/ice-cream/di)[ Docs](http://adambalan.com/)[ RSS](/packages/ice-cream-di/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (4)Dependencies (5)Versions (6)Used By (0)

Ice Cream DI
============

[](#ice-cream-di)

[![Build Status](https://camo.githubusercontent.com/26322b2bd570c69fb5b84fac42baf219b5ad658b52d3b646ce3e94fe13e3c452/68747470733a2f2f7472617669732d63692e6f72672f4164616d4b796c652f6963652d637265616d2d64692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/AdamKyle/ice-cream-di)[![Packagist](https://camo.githubusercontent.com/b20de6762f08b834e4b36d55f645755b0e7b538a54c80a8075291e01c2d345e7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6963652d637265616d2f64692e7376673f7374796c653d666c6174)](https://packagist.org/packages/ice-cream/di)![Maintenance](https://camo.githubusercontent.com/bc62a4386260fb7a4c9f5e3977f2f2bf876ad0374f462e723cedd156953a0da4/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323031382e737667)![Made With Love](https://camo.githubusercontent.com/8e692b7ce6dc41cb29efb7aa471b6e72a0a009ff99bf93ca83023a3da4e177b8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d616465253230576974682d4c6f76652d677265656e2e737667)

- Requires PHP 7.2.x
- Is Standalone

I wanted a simple and effective way to replicate [pimple](http://pimple.sensiolabs.org/#modifying-services-after-definition) and create DI at it's most basic level.

The core concept is simple, you have a container that you can add items to and fetch via the [ArrayAccess](http://php.net/manual/en/class.arrayaccess.php) interface.

We also allow you to create factories, which allow you to return new instances of the object each time instead of the same object every time.

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

[](#documentation)

You can view this packages documentation [here](https://github.com/AdamKyle/ice-cream-di/blob/master/docs/ApiIndex.md)

Philosophy
----------

[](#philosophy)

Ice Cream is not meant to be the next big thing in OSS. It is essentially Pimple plagiarized.

I wanted to build a simple DI container that I could use in my own projects to try and better understand DI at a fundamental level.

Examples:
---------

[](#examples)

The following is a super basic example of how to use the container.

```
use IceCreamDI\Container;

$container = new Container();

$container['service'] = function($c) {
  return new Service();
}

$container['services'] // Returns instance of Service class.
```

> ATTN!!
>
> We pass the instance of the container to all of our closures, this is exactly like pimple. Even when it comes to extending the already registered service provider you can be sure that the new extension will also have the container object.

Even more simpler:

```
$container = new Container([
  'app.service' => function ($c) {
    return new Service();
  },
]);
```

> ATTN!
>
> Should you have something in the container with the same name and you throw in another object under the same name you will break your container. Make sure your names are unique.

> ATTN!
>
> You cannot manipulate a container object after its been called, for example:
>
> ```
> $container = new Container();
> $container['service'] = function ($c) { return new Service(); };
>
> $service = $container['service'];
>
> $container->extend('service', function($service){ $service->someMethodCall(); });
> ```
>
>
>
> The above will error out, because when you "build" the item from the service container, we lock it in place.

What if you want to extend an already registered item in the container? Well we can do the following:

```
use IceCreamDI\Container;

$container = Container();

$container['service'] = function($c) {
  return new Service();
}

$container->extend('service', function($service){
  $service-> ....

  ....

  return $service;
});
```

This allows you to easily register and then manipulate items in the container.

If you just want the closure back, you can call the raw method:

```
use IceCreamDI\Container;

$container = Container();

$container['service'] = function($c) {
  return new Service();
}

$container->raw('service'); // => closure instance.
```

When you call the factory method, you will **always** get a new instance of the registered object. For instance:

```
use IceCreamDI\Container;

$container = Container();

$container['service'] = $container->factory(function($c) {
  return new $service();
});

$container['service']; // => Will be a new instance every time.
```

Where as with the the regular `$container['service']` you will always get the same object back.

What if you have a factory that has dependencies? For example, assume you have a class that each time it's called, you need to inject dependencies into the class. You can use the `resolveFactory` method:

```
use IceCreamDI\Container;

$container = Container();

$container['service_deps'] = [
  'dep1' => ...,
  ...
];

// Notice how you even have access to the containe object $c.
$container['service'] = $container->factory(function($dep1, $dep2, ..., $c) {
  return new $service($dep1, $dep2, ...);
});

$container->resolveFactory('service', 'service_deps'); // Gives you a new service instance with deps passed in.
```

As you see above we inject the dependencies. We even add on an addition dependency which is the `$c` container object dependency so that the registered factory that will be resolved has a instance of the container.

We can also call a method on a container object:

```
use IceCreamDI\Container;

$container = Container();

$container['service'] = function() { return new Service(); };

$container->call('service', 'process'); // Same as doing: $container['service']->process();
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

5

Last Release

3027d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.0.0

1.2.1PHP &gt;=7.2.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/188563?v=4)[AdamBalan](/maintainers/AdamKyle)[@AdamKyle](https://github.com/AdamKyle)

---

Top Contributors

[![AdamKyle](https://avatars.githubusercontent.com/u/188563?v=4)](https://github.com/AdamKyle "AdamKyle (16 commits)")

---

Tags

dependency-injectionlibrarydidependency management

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[yiisoft/injector

PSR-11 compatible injector. Executes a callable and makes an instances by injecting dependencies from a given DI container.

943.2M46](/packages/yiisoft-injector)[mouf/mouf

The Mouf PHP framework: an open-source PHP framework providing an easy way to download, install, use and reuse components, with a graphical user interface.

55146.3k17](/packages/mouf-mouf)[mouf/pimple-interop

This project is a very simple extension to the Pimple microframework. It adds to Pimple compatibility with the container-interop APIs.

102.5M2](/packages/mouf-pimple-interop)[joomla/di

Joomla DI Package

15417.5k12](/packages/joomla-di)[utopia-php/registry

A simple dependency management library for PHP

17281.1k4](/packages/utopia-php-registry)[mouf/picotainer

This package contains a really minimalist dependency injection container compatible with container-interop.

16190.7k11](/packages/mouf-picotainer)

PHPackages © 2026

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