Skip to content

Services

Kyle Spraggs edited this page Jul 20, 2014 · 17 revisions

Services

Services in SpiffyFramework are managed by the SpiffyInject component. SpiffyInject is SpiffyFramework's light-weight inversion of control container and is part of the foundation to the entire framework.

SpiffyInject also manage's package parameters. You can read more about this feature in the package documentation.

The basics

You can create services in the following ways:

  • Setting using a string class name
  • Setting the service directly
  • Creating the service through a factory closure
  • Using the array configuration
  • Using an object that implements ServiceFactory

All services are set through the nject() method regardless of which style you choose. Each style has it's own advantages and disadvantages. It's you to you to decide which is the best approach to take for your application.

By default, each package loads services using the services.php file in config/services.php. Below is a simple example of the config/services.php file.

// file: package_name/config/services.php
// 'service_name' => 'service_specification'
return [
    'application.service' => 'Application\Service',
];

Setting Services