PHPackages                             viragrajput/virag-container - 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. viragrajput/virag-container

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

viragrajput/virag-container
===========================

A container package for dependency injection

v1.1.2(2y ago)010MITPHPPHP ^7.4 || ^8.0

Since Mar 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ViragRajput/Virag-Container)[ Packagist](https://packagist.org/packages/viragrajput/virag-container)[ RSS](/packages/viragrajput-virag-container/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (0)

Virag Container
===============

[](#virag-container)

Virag Container is a versatile and lightweight dependency injection container designed to streamline the management of class dependencies and service resolution within PHP applications.

With Virag Container, you gain access to a comprehensive set of features essential for effective dependency management. This includes binding classes and interfaces to concrete implementations, resolving dependencies, defining singleton bindings, and managing contextual bindings. Additionally, advanced functionalities such as service providers, custom resolvers, inflectors, auto-wiring, and factories are seamlessly integrated, providing flexibility and extensibility.

Moreover, Virag Container is built with performance in mind, ensuring minimal overhead and optimal efficiency in your application. Whether you're building a small project or a large-scale application, Virag Container offers the tools you need to organize and maintain your codebase effectively.

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

[](#installation)

You can install Virag Container via Composer. Run the following command in your terminal:

```
composer require viragrajput/virag-container
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

First, create an instance of the container:

```
use Virag\Container\Container;

$container = new Container();
```

#### Binding Classes or Interfaces

[](#binding-classes-or-interfaces)

You can bind classes or interfaces to concrete implementations using the `bind` method:

```
$container->bind('LoggerInterface', 'FileLogger');
```

#### Resolving Dependencies

[](#resolving-dependencies)

To resolve dependencies, use the `make` method:

```
$logger = $container->make('LoggerInterface');
```

This will resolve the `FileLogger` instance.

#### Singleton Bindings

[](#singleton-bindings)

Singleton bindings can be defined using the `singleton` method:

```
$container->singleton('DatabaseConnection', function () {
    return new DatabaseConnection();
});
```

#### Constructor Injection

[](#constructor-injection)

The container supports constructor injection. For example:

```
class UserRepository
{
    protected $db;

    public function __construct(DatabaseConnection $db)
    {
        $this->db = $db;
    }
}

$container->bind('UserRepository', 'UserRepository');

$userRepository = $container->make('UserRepository');
```

#### Contextual Bindings

[](#contextual-bindings)

You can define contextual bindings using the `when` and `needs` methods:

```
$container->when('PaymentGateway')
          ->needs('LoggerInterface', 'PaymentLogger');
```

### Advanced Usage

[](#advanced-usage)

#### Service Providers

[](#service-providers)

You can register service providers to bootstrap your application:

```
$container->addServiceProvider('App\Providers\DatabaseServiceProvider');
```

#### Custom Resolvers

[](#custom-resolvers)

Define custom resolvers for specific bindings:

```
$container->registerCustomResolver('MailService', function ($container) {
    return new ExternalMailService($container->make('Config')->get('mail.api_key'));
});
```

#### Inflectors

[](#inflectors)

Inflectors allow you to modify instances after instantiation:

```
$container->addInflector('LoggerAwareInterface', function ($loggerAware) use ($container) {
    $loggerAware->setLogger($container->make('Logger'));
});
```

#### Auto-Wiring

[](#auto-wiring)

Enable auto-wiring to automatically resolve class dependencies:

```
$container->enableAutoWiring();
```

#### Factories

[](#factories)

Use factories for dynamic instance creation:

```
$container->bindFactory('PaymentGateway', function ($container) {
    return new PaymentGateway($container->make('Config')->get('payment.gateway'));
});
```

Examples:
---------

[](#examples)

Explore various usage examples of the Virag Container Package in the "Docs" folder within this repository. These examples cover a wide range of scenarios to help you understand how to utilize the features of the package effectively.

Contributing
------------

[](#contributing)

We welcome contributions from the community! If you have any suggestions, find bugs, or want to add new features, please don't hesitate to submit issues or pull requests. Your contributions help improve the package for everyone. Let's build something great together!

License
-------

[](#license)

Virag Container is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Total

5

Last Release

769d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dad689e5f68ca906d4ac7685da9de4ecbd6703ce6dc4e690c95fe4f8aa817fea?d=identicon)[viragrajput](/maintainers/viragrajput)

---

Top Contributors

[![ViragRajput](https://avatars.githubusercontent.com/u/108286928?v=4)](https://github.com/ViragRajput "ViragRajput (13 commits)")

---

Tags

containerdependency-injectioninversion of control

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/viragrajput-virag-container/health.svg)

```
[![Health](https://phpackages.com/badges/viragrajput-virag-container/health.svg)](https://phpackages.com/packages/viragrajput-virag-container)
```

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[php-di/php-di

The dependency injection container for humans

2.8k48.9M995](/packages/php-di-php-di)[aura/di

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

356968.3k58](/packages/aura-di)[acclimate/container

Provides adapters for various third-party service containers.

219390.6k15](/packages/acclimate-container)[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3611.7M3](/packages/mrclay-props-dic)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)

PHPackages © 2026

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