PHPackages                             inanepain/servicemanager - 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. inanepain/servicemanager

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

inanepain/servicemanager
========================

Factory-driven dependency injection container.

0.2.0(4mo ago)12UnlicensePHPPHP &gt;=8.4

Since Feb 23Pushed 1mo agoCompare

[ Source](https://github.com/inanepain/servicemanager)[ Packagist](https://packagist.org/packages/inanepain/servicemanager)[ Docs](https://github.com/inanepain/servicemanager)[ RSS](/packages/inanepain-servicemanager/feed)WikiDiscussions develop Synced today

READMEChangelog (2)Dependencies (3)Versions (4)Used By (0)

inanepain/servicemanager [![icon](./icon.png "inanepain/stdlib")](./icon.png)
=============================================================================

[](#inanepainservicemanager-)

Table of Contents

- [![icon](./icon.png "inanepain/servicemanager") inanepain/servicemanager](#inanepainservicemanager)
- [1. Install](#install)
- [2. Overview](#overview)
    - [2.1. Lifecycle: `get()` vs `build()`](#lifecycle-get-vs-build)
    - [2.2. Errors](#errors)
    - [2.3. API Summary](#api-summary)
- [3. Usage](#usage)
    - [3.1. Quickstart](#quickstart)
    - [3.2. Transient services with `build()`](#transient-services-with-build)
    - [3.3. Factories can resolve dependencies](#factories-can-resolve-dependencies)
    - [3.4. Bulk registration with `createServiceManager()`](#bulk-registration-with-createservicemanager)
    - [3.5. Missing services](#missing-services)

[![icon](./icon.png "inanepain/servicemanager")](./icon.png) inanepain/servicemanager
-------------------------------------------------------------------------------------

[](#-inanepainservicemanager)

Factory-driven dependency injection container.

1. Install
----------

[](#1-install)

composer

```
composer require inanepain/servicemanager
```

2. Overview
-----------

[](#2-overview)

`inanepain/servicemanager` is a small, factory-driven dependency injection container.

At its core, a `ServiceManager` is a registry of **services** identified by a string name. Each service is produced by a **factory** (a `callable`).

The factory signature is intentionally simple:

function (\\Inane\\ServiceManager\\ServiceManager $sm): mixed

Passing the `ServiceManager` to factories enables dependency resolution inside the factory (e.g. `$sm→get('config')`).

### 2.1. Lifecycle: `get()` vs `build()`

[](#21-lifecycle-get-vs-build)

The `ServiceManager` supports two retrieval modes:

- `get($name)` returns a **cached** instance.

    - The first call builds the service via its factory and stores the result.
    - Subsequent calls return the same instance.
- `build($name)` always returns a **new** instance.

This makes it easy to mix singleton-style services (via `get()`) with transient services (via `build()`).

### 2.2. Errors

[](#22-errors)

If a service name is not registered, `get()` and `build()` throw `Inane\ServiceManager\Exception\NotFoundException` (implements `Psr\Container\NotFoundExceptionInterface`) with the message `Service '{name}' not found.`.

### 2.3. API Summary

[](#23-api-summary)

- `ServiceManager::createServiceManager(OptionsInterface $services): static`

    - Convenience factory that registers each entry in an `OptionsInterface` mapping.
- `register(string $name, callable $factory): void`

    - Registers a service factory under the given name.
- `get(string $name): mixed`

    - Returns the cached service instance.
- `build(string $name): mixed`

    - Builds and returns a new service instance.

3. Usage
--------

[](#3-usage)

### 3.1. Quickstart

[](#31-quickstart)

Register a service with `register()` and fetch it with `get()`:

&lt;?php

declare(strict\_types=1);

require\_once 'vendor/autoload.php';

use Inane\\ServiceManager\\ServiceManager;

$sm = new ServiceManager();

$sm→register('now', static fn (ServiceManager $sm) ⇒ new DateTimeImmutable('now'));

$a = $sm→get('now'); $b = $sm→get('now');

var\_dump($a === $b);

### 3.2. Transient services with `build()`

[](#32-transient-services-with-build)

Use `build()` when you want a new instance each time:

&lt;?php

declare(strict\_types=1);

require\_once 'vendor/autoload.php';

use Inane\\ServiceManager\\ServiceManager;

$sm = new ServiceManager();

$sm→register('uuid', static fn (ServiceManager $sm) ⇒ bin2hex(random\_bytes(16)));

$a = $sm→build('uuid'); $b = $sm→build('uuid');

var\_dump($a !== $b);

### 3.3. Factories can resolve dependencies

[](#33-factories-can-resolve-dependencies)

Factories receive the `ServiceManager` instance, so they can depend on other services:

&lt;?php

declare(strict\_types=1);

require\_once 'vendor/autoload.php';

use Inane\\ServiceManager\\ServiceManager; use Psr\\Log\\NullLogger;

$sm = new ServiceManager();

$sm→register('logger', static fn (ServiceManager $sm) ⇒ new NullLogger());

$sm→register('worker', static function (ServiceManager $sm) { $logger = $sm→get('logger');

```
    return new class($logger) {
        public function __construct(private object $logger) {}
    };
});
```

$worker = $sm→get('worker');

### 3.4. Bulk registration with `createServiceManager()`

[](#34-bulk-registration-with-createservicemanager)

If you already have a mapping of service names to factories, you can create and populate a manager in one step.

&lt;?php

declare(strict\_types=1);

require\_once 'vendor/autoload.php';

use Inane\\ServiceManager\\ServiceManager; use Inane\\Stdlib\\Options;

$services = new Options(\[ 'config' ⇒ static fn (ServiceManager $sm) ⇒ new Options(\['env' ⇒ 'dev'\]), 'answer' ⇒ static fn (ServiceManager $sm) ⇒ 42, \]);

$sm = ServiceManager::createServiceManager($services);

var\_dump($sm→get('answer'));

### 3.5. Missing services

[](#35-missing-services)

If you call `get()` or `build()` with an unregistered name, an `Inane\ServiceManager\Exception\NotFoundException` (PSR-11 `Psr\Container\NotFoundExceptionInterface`) is thrown.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance86

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

130d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1823594?v=4)[Philip Michael Raab](/maintainers/inanepain)[@inanepain](https://github.com/inanepain)

---

Top Contributors

[![inanepain](https://avatars.githubusercontent.com/u/1823594?v=4)](https://github.com/inanepain "inanepain (17 commits)")

---

Tags

containerinaneinanepainlibrarypsr-11service-managercontainerPSR-11libraryservicemanagerinaneinanepain

### Embed Badge

![Health badge](/badges/inanepain-servicemanager/health.svg)

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.9k55.5M1.2k](/packages/php-di-php-di)[laminas/laminas-servicemanager

Factory-Driven Dependency Injection Container

16058.7M810](/packages/laminas-laminas-servicemanager)[slince/di

A flexible dependency injection container

20272.1k6](/packages/slince-di)[infocyph/intermix

A lightweight PHP DI container, invoker, serializer, and utility toolkit.

137.7k2](/packages/infocyph-intermix)

PHPackages © 2026

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