Add a new service to the wrapper

@param string  $name
@param Closure $closure

@return $this
@throws ServiceAlreadyExists
188229
public function add($name, Closure $closure)
  {
    if (!$this->has($name)) {
      $service = new Service();

      $closure($service);

      $this->services[$name] = $service;

      return $this;
    }

    throw new ServiceAlreadyExists("Service '" . $name . "' already exists.");
  }
462331
public function addResolver(string $name, callable $callback)
    {
        //if it's a closure, they meant to bind the callback
        if ($callback instanceof Closure) {
            //so there's no scope
            $callback = $callback->bindTo($this, get_class($this));
        }

        $this->getResolverHandler()->register($name, $callback);

        return $this;
    }
958051
public function aggregate(\Closure $closure)
    {
        $builder = new AggregationBuilder($this->query);

        $closure($builder);

        return $this;
    }
1290153
public function onBoot($name, Closure $callback)
    {
        $priority              = $this->getPluginPriority($name, 1);
        $this->bootCallbacks[] = compact('name', 'priority', 'callback');
    }
93230
public static function from(Closure $closure)
    {
        if (static::$context === null) {
            $instance = new static($closure);
        } elseif (isset(static::$context->scope[$closure])) {
            $instance = static::$context->scope[$closure];
        } else {
            $instance = new static($closure);
            static::$context->scope[$closure] = $instance;
        }

        return $instance;
    }
952415
public function create($name, Closure $resolver)
    {
        $builder = new MenuBuilder($name, $this->config);

        $builder->setViewFactory($this->views);

        $this->menus[$name] = $builder;

        return $resolver($builder);
    }
1121047
public function resolveCallableString(string $name, callable $closure, $factory = false)
    {
        if($factory === true) {
            return $this->resolveCallable($name, $closure);
        }

        return $this->resolveCallableFromCache($name, $closure);
    }
402693
public function add($name, \Closure $closure)
    {
        $test = new Test($name, $closure);
        $this->addTest($test);

        return $test;
    }
415159
public function addMethod(string $name, Closure $callback): Package
    {
        $this->methods[$name] = $callback->bindTo($this, get_class($this));

        return $this;
    }
258399
public function set($name, \Closure $extension)
    {
        if (!is_string($name)) {
            throw new \InvalidArgumentException(self::MSG_EXTENSION_NAME, 210);
        }

        parent::offsetSet(strtolower($name), $extension);
        
        return $this;
    }
614060
public function share(Closure $closure)
		{
			return function($Eventable) use ($closure) {
				// We'll simply declare a static variable within the Closures and if it has
				// not been set we will execute the given Closures to resolve this value
				// and return it back to these consumers of the method as an instance.
				static $object;
				if (is_null($object)) {
					$object = $closure($Eventable);
				}
				return $object;
			};
		}
414653
public function tweakApplication(Closure $closure): void
    {
        $closure($this->app);

        static::$server->stash([
            'class' => static::class,
            'tweakApplication' => serialize(SerializableClosure::from($closure)),
        ]);
    }
750640
public function given($name, $closure)
    {
        if (isset(static::$_blacklist[$name])) {
            throw new Exception("Sorry `{$name}` is a reserved keyword, it can't be used as a scope variable.");
        }

        $given = new Given($closure);
        if (array_key_exists($name, $this->_given)) {
            $given->{$name} = $this->_given[$name](Suite::current()->scope());
        }
        $this->_given[$name] = $given;
        return $this;
    }
134154
public function make($name, Closure $callback)
    {
        $this->add($name, Menu::make($name, $callback));
    }
1033866
public function setService($name, $service, $parameters = null)
    {
        $name = strtolower($name);
        if ($service instanceof \Closure) {

            /**
             * Save directly the service in the
             * container.
             */
            $this->registerService($name, $service);

        } elseif (class_exists($service, true)) {

            /**
             * instantiation and initialization of
             * each service, return true on success
             * and false on error
             */
            $this->registerService($name, new $service($parameters));
        }
        return $this;
    }
741782
public function resolveClosure(\Closure $closure)
    {
        $reflection = new \ReflectionFunction($closure);

        $dependencies = $reflection->getParameters();
        $instances = $this->resolveDependencies($dependencies); // Actually resolve the dependencies
        $o = $reflection->invokeArgs($instances);

        return $o;
    }
225785
private function resolve($name)
    {   
        // set as resolved
        $this->resolved[$name] = true;
        
        // resolve the service
        if (is_string($this->instances[$name]) && class_exists($this->instances[$name])) 
        {
            
            $object = $this->instances[$name];

            return new $object();

        }
        elseif(is_callable($this->instances[$name]))
        {

            $callable = $this->instances[$name];

            return $callable();

        }    

        return $this->instances[$name];
    }