/**
 * srvoa - soa infrastructure for node js
 *
 * @copyright   Copyright (c) 2015, Alrik Zachert
 * @license     https://gitlab.com/a-z/node-srvoa/blob/master/LICENSE BSD-2-Clause
 */

"use strict";

/**
 * The srvoa service manager.
 * It is responsible for holding the service registry and giving shared access to the service instances.
 */
class ServiceManager {
    /**
     * The map of key => service.
     *
     * @property services {Object}
     */

    /**
     * Initialize services map.
     *
     * @constructor
     */
    constructor() {
        this.services = {};
    }

    /**
     * Lookup and return a service by its key.
     *
     * @param   {String} key
     * @return  {Object}|{undefined}
     */
    get(key) {
        return this.services[key];
    }

    /**
     * Store a service for the given key.
     *
     * @param   {String} key
     * @param   {Object} service
     * @return  {ServiceManager}
     */
    set(key, service) {
        this.services[key] = service;

        return this;
    }

    /**
     * Delete the service for the given key.
     *
     * @param   {String} key
     * @return  {ServiceManager}
     */
    remove(key) {
        delete this.services[key];

        return this;
    }

    /**
     * Check for the existence of a service by its key.
     *
     * @param   {String} key
     * @return  {Boolean}
     */
    has(key) {
        return (key in this.services);
    }
}

module.exports = ServiceManager;

@@ -667,32 +667,170 @@
    %7BString%7D key%0A
+     * @param   %7BBoolean%7D strict (optional) default false%0A     * @throws  %7BError%7D if strict mode is enabled and there is no such service.%0A
      * @return  
@@ -865,28 +865,190 @@
 %0A    get(key
+, strict
 ) %7B%0A
+        if (strict === true && !this.has(key)) %7B%0A            throw new Error(%60Cannot return unknown service for key: $%7Bkey%7D in strict mode.%60);%0A        %7D%0A%0A
         retu
@@ -1196,16 +1196,172 @@
 service%0A
+     * @param   %7BBoolean%7D strict (optional) default false%0A     * @throws  %7BError%7D if strict mode is enabled and a service for the given key already exists.%0A
      * @
@@ -1413,20 +1413,178 @@
  service
+, strict
 ) %7B%0A
+        if (strict === true && this.has(key)) %7B%0A            throw new Error(%60Cannot re-register service for key: $%7Bkey%7D in strict mode.%60);%0A        %7D%0A%0A
         
@@ -1743,58 +1743,278 @@
  * @
-return  %7BServiceManager%7D%0A     */%0A    remove(key) %7B
+param   %7BBoolean%7D strict (optional) default false%0A     * @return  %7BServiceManager%7D%0A     */%0A    remove(key, strict) %7B%0A        if (strict === true && !this.has(key)) %7B%0A            throw new Error(%60Cannot remove unknown service for key: $%7Bkey%7D in strict mode.%60);%0A        %7D%0A
 %0A   

introduce strict parameter on service-manager api