Skip to content

CustomRelativeServiceDirectory

Mauro Gadaleta edited this page Mar 28, 2019 · 1 revision

Custom relative service directory

If all your application starts from the same source directory may will be easy for you to add a custom relative service directory

Imagine you have the following directory structure

  • config/services.yml
  • src/Kernel.js
  • src/services/SomeCoolManager.js
  • src/authorization/Authentication.js

Instead of defining a relative path from your services.yml you can actually set a starting point for your dependencies.

Kernel file

import {ContainerBuilder}
import path from 'path';

const srcDir = path.join(__dirname);
const container = new ContainerBuilder(true, srcDir);

So, basically, the second parameter when ContainerBuilder is instantiate is the source directory. Then your configuration file will look like this:

services:
    app.SomeCoolManager:
        class: services/SomeCoolManager

    app.Authentication:
        class: authorization/Authentication