Application Services

The application object behaves as a service container, that means we can register and retrieve services directly from it.

Services Interface


Accessing a service manager.

/** @var \Zend\ServiceManager\ServiceManager $services */
$services = $app->getServices();


Getting a service from application.

/** @var \MyService $service */
$service = $app->get('MyService');


Registering a service into application.

// registering an invokable

// registering a factory
$app->set('MyService', MyServiceFactory::class);

// registering a factory object
$app->set('MyService', new MyServiceFactory);

// registering a closure factory
$app->set('MyService', function () {
    return new MyService;

// setting an object
$app->set('MyService', new MyService);


Checking wheater a service is available to application.

/** @var bool $hasService */
$hasService = $app->has('MyService');

Services Config


Configuring services.

use WebinoAppLib\Feature\Config;
use WebinoAppLib\Feature\Service;

    // invokable
    new Service(MyService::class),
    // factory
    new Service(MyService::class, MyServiceFactory::class),


Application core service config feature.

use WebinoAppLib\Feature\CoreService;

    // invokable
    new CoreService(MyCoreService::class),
    // factory
    new CoreService(MyCoreService::class, MyCoreServiceFactory::class),