This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

A Laravel inspired way to register services into your yii application.

1.0.0 2016-05-12 10:30 UTC

This package is auto-updated.

Last update: 2021-11-29 02:17:38 UTC


Provides a Laravel-inspired way to register services into a Yii application.


Require the library via Composer.

composer require sassnowski/yii-provider-registry


Change the last few lines in your web/index.php to this:

$app = new yii\web\Application($config)

(new \Sassnowski\Yii2\ProviderRegistry\ProviderRegistry(\Yii::$container))->bootstrap();


Create a bootstrap folder in your application root and put a services.php file into it. This file should simply return an array of Bootstrapper classes.


return [

These classes should implement a bootstrap method. This method will be called during the bootstrapping process and receives the applications DI Container as its only parameter. Inside this method you can then register classes into the Yii DI Container.


namespace Acme\Providers;

use yii\di\Container;

class MyProvider
    public function bootstrap(Container $container)

That's it! Now you can use the service anywhere inside the application either by explicitly resolving it out of the container via get or by type hinting it in the constructor. Refer to the (Yii Documentation)[] for the full list of possibilities!