PHPackages                             anonymous-php/simple-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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. anonymous-php/simple-di

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

anonymous-php/simple-di
=======================

Simple Dependency Resolving and Injection Container

1.1.3(8y ago)232MITPHP

Since Mar 2Pushed 8y agoCompare

[ Source](https://github.com/anonymous-php/simple-di)[ Packagist](https://packagist.org/packages/anonymous-php/simple-di)[ RSS](/packages/anonymous-php-simple-di/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (1)Versions (9)Used By (0)

Simple DI
=========

[](#simple-di)

Actually this library is more about the dependency container than auto-wiring but don't worry auto-wiring is there. You have the possibility to create instances of classes with auto-wiring of their arguments and to inject dependencies to called methods.

### History

[](#history)

I like PHP-DI very much but when I started new project I understood it needs another approach of determining it's definitions and dependencies. I wanted to have the simplest as possible syntax of definitions and powerful, but not complex at the same time, mechanism of injection. So I just wrote my own DI.

### Peculiarities

[](#peculiarities)

I didn't want to wrap any definition to unnecessary functions which just marks this definition as an instantiable class. I already know what is it while write a code and I want to decide how to use this information in my application.

My colleague asked me about the primitives injection in my library. I don't think is a good idea. Just make the dependency for the Container and get the value you need. Keep this type of values under control by yourself.

### Compatibility

[](#compatibility)

Auto-wiring is DISABLED by default.

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

[](#installation)

```
composer require anonymous-php/simple-di

```

Methods
-------

[](#methods)

Сlass `Container` implements `\Psr\Container\ContainerInterface` interface so it has two methods `has($id)` which works as usual and `get($id)` which can has the behavior different from your preferred library. There is the method `set($id, $value)` which does exactly the same it means.

### get($id)

[](#getid)

The method responds with a primitive with the only one exception - Closures. In case of Closure the library resolves it with the injection of it's dependencies. The Closure may to return any primitive or an instance of any class you wish. This method caches results of the resolving.

```
