PHPackages                             swiftly/dependency - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. swiftly/dependency

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

swiftly/dependency
==================

Straightforward dependency injection.

0491PHP

Since Apr 7Pushed 1mo agoCompare

[ Source](https://github.com/SwiftlyPHP/dependency)[ Packagist](https://packagist.org/packages/swiftly/dependency)[ RSS](/packages/swiftly-dependency/feed)WikiDiscussions main Synced 6d ago

READMEChangelogDependenciesVersions (2)Used By (1)

Swiftly - Dependency
====================

[](#swiftly---dependency)

[![PHP Version](https://camo.githubusercontent.com/983ae72c436b80b073bcbb7a25e3fb4f47d0dd0dbf41e6af7d11881b4ebdac72/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e342d626c7565)](https://www.php.net/supported-versions)[![CircleCI](https://camo.githubusercontent.com/42fdf71cc982e795e08cc4d04766c93330e7db104e9971b539c5017674c5620d/68747470733a2f2f636972636c6563692e636f6d2f67682f53776966746c795048502f646570656e64656e63792f747265652f6d61696e2e7376673f7374796c653d736869656c64)](https://circleci.com/gh/SwiftlyPHP/dependency/tree/main)[![Coverage Status](https://camo.githubusercontent.com/18ebe2a0b55ffd2b72a985ab2c0c2857d10031cf894ad3a48e6c7b3e76dd3439/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f53776966746c795048502f646570656e64656e63792f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/SwiftlyPHP/dependency?branch=main)

Construct object hierarchies with ease.

Designed to be used primarily for [SwiftlyPHP](https://github.com/SwiftlyPHP)projects, this component provides a lightweight implementation of a dependency container and injector, allowing you to easily configure and build complex object trees with minimal fuss.

While not as fully-featured as some containers such as Symfony's or Laravel's, this component offers a minimal, easy to use interface for managing dependencies.

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

[](#installation)

To install the library use [Composer](https://getcomposer.org/):

```
composer require swiftly/dependency
```

Usage
-----

[](#usage)

### The Basics

[](#the-basics)

If you've ever worked on a sizeable project, you will know the benefit of splitting your code into well-delineated classes. While this bears a practical benefit in making the filesystem (and project structure) cleaner, it also allows us to separate out related areas of concern, grouping related functionality together in a way that is easy to reason about and is composable.

Over time however, you'll likely end up with a lot of classes. Objects will start to rely on other objects. You end up with constructors that require two or three objects, whose own constructors take the same again, quickly spirally into a hierarchy that is complicated to manage.

Enter the service container:

```
