PHPackages                             antriver/laravel-singleton-discovery - 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. antriver/laravel-singleton-discovery

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

antriver/laravel-singleton-discovery
====================================

1.0.4(6y ago)09[3 PRs](https://github.com/antriver/laravel-singleton-discovery/pulls)MITPHPPHP &gt;=7.1

Since Jan 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/antriver/laravel-singleton-discovery)[ Packagist](https://packagist.org/packages/antriver/laravel-singleton-discovery)[ RSS](/packages/antriver-laravel-singleton-discovery/feed)WikiDiscussions master Synced today

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

Laravel Singleton Auto Discovery
================================

[](#laravel-singleton-auto-discovery)

Automatically registers your classes as singletons in Laravel's DI container.

### The Problem

[](#the-problem)

In Laravel by default if you have something injected by calling `app(SomeClass::class)` or `App::make(SomeClass::class)` or by a type hint on a method, it will give you a new instance of that class each time. e.g.

```
app(SomeClass::class) === app(SomeClass::class); // false
```

To solve this you need to explicitly tell the DI container that you want `SomeClass` to be a singleton, like this:

```
app()->singleton(SomeClass::class);
```

If you have lots of classes you want to be singletons it gets tedious to have to write the `app()->singleton()` call for every one.

### The Solution

[](#the-solution)

This package automatically scans your `app` directory for any classes that implement the `SingletonInterface` interface. For any it finds it registers them as a singleton with the DI container.

This is very similar to the pattern that Laravel's built in event discovery follows (since 5.8.9).

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

[](#installation)

```
composer require antriver/laravel-singleton-discovery

```

Add `SingletonDiscoveryServiceProvider` to your list of providers in `config/app.php`:

```
    'providers' => [
        // ...
        Antriver\LaravelSingletonDiscovery\SingletonDiscoveryServiceProvider::class,
        // ...
    ],
```

Commands
--------

[](#commands)

The directory will be scanned each time the app starts up. This is probably what you want during development but will affect performance in production. You can use the `singletons:cache` command to cache the discovered singletons to avoid that. The `singletons:clear` command clears the cached file.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

5

Last Release

2316d ago

### Community

Maintainers

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

---

Top Contributors

[![antriver](https://avatars.githubusercontent.com/u/251159?v=4)](https://github.com/antriver "antriver (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/antriver-laravel-singleton-discovery/health.svg)

```
[![Health](https://phpackages.com/badges/antriver-laravel-singleton-discovery/health.svg)](https://phpackages.com/packages/antriver-laravel-singleton-discovery)
```

###  Alternatives

[tightenco/ziggy

Use your Laravel named routes in JavaScript.

4.3k41.6M267](/packages/tightenco-ziggy)[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

97139.6k2](/packages/nickurt-laravel-akismet)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)

PHPackages © 2026

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