Register a service

@param object $service
@param string $name
774043
public function registerService($service, $name = '') {
        if (empty($name)) {
            $name = Assist::classNameShort($service);
        }

        static::$container->offsetSet(strtolower($name), $service);
    }
141395
function configure(name, service) {
	if (!name) {
		throw new Error('Please specify a name for the client');
	}
	if (name === 'configure' || name === 'client') {
		throw new Error('Cannot register service with reserved name: ' + name);
	}
	module.exports[name] = new Client(service);
}
252153
public function setLibrary($name, $service, $parameters = null)
    {
        return $this->setService($name, $service, $parameters);
    }
1160366
public static function factory($name)
    {
        if (!isset(self::$services[$name])) {
            throw new \RuntimeException("The service [$name] don't register.");
        }

        $service = self::$services[$name];

        if (\is_object($service) && method_exists($service, '__invoke')) {
            return $service();
        }

        return $service;
    }
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;
    }
31795
public function isRegistered($name)
    {
        return
            array_key_exists($name, $this->services)
            || (
                isset($this->serviceProviders[$name])
                && $this->serviceProviders[$name] instanceof ServiceProviderInterface
            );
    }
1036377
protected function registerPlugin($name)
    {
        $view = $this->getView();

        BootstrapPluginAsset::register($view);

        $id = $this->options['id'];

        $options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
        $js = "jQuery('#$id').$name($options);";
        $view->registerJs($js);
    }
830388
protected function registerInstance($key, $name, $interface)
    {
        if (is_a($name, $interface, true)) {
            $instances = $this->getOption($key);
            if ($instances === null || array_search($name, $instances) === false) {
                $instances[] = $name;
                $this->setOption($key, $instances);
                $this->registerMetadataService();
            }
        }
    }
1127345
public function register($name, $service, $args = [], $isParam = false)
    {
        if (!$isParam && !$this->hasService($name)) {
            $this->registeredList['services'][$name] = [
                'class' => $service,
                'arguments' => $args,
            ];

            return true;
        } elseif ($isParam && !$this->hasParam($name)) {
            $this->registeredList['params'][$name] = $service;

            return true;
        }

        return false;
    }
1175350
public function registerService($service, $class)
    {
        $this[$service] = function ($app) use ($class) {
                $inst = new $class;
                if ($inst instanceof FactoryInterface) {
                    return $inst->create($app);
                } else {
                    return $inst;
                }
            };
    }
945333
protected function registerMetadataService()
    {
        if ($this->getServiceLocator()->has(MetadataService::SERVICE_ID)) {
            $metadataService = $this->getServiceLocator()->get(MetadataService::SERVICE_ID);
        } else {
            $metadataService = $this->getServiceManager()->build(MetadataService::class);
        }
        $metadataService->setOption(MetadataService::IMPORTER_KEY, $this);
        $this->getServiceManager()->register(MetadataService::SERVICE_ID, $metadataService);
    }
750811
public function add($service, $offset = null)
    {
        if (is_object($service)) {
            if ( ! $service instanceof SplServiceRegistry) {
                $service = new SplServiceRegistry($service);
            }
        }

        if (profiler() !== false) {
            profiler()->watch('Add New Service: ' . $service->getClassName());
        }

        $this->register($service, $offset);
    }
780838
public function registerInstance($name = null)
    {
        if ($name === null) {
            $name = 'default';
        }
        $this->instanceName($name);
        return $this;
    }
237387
public function register($name)
    {
        $this->hook->action($name, function () {
            if (! $this->nonceValid()) {
                wp_send_json($this->getErrorMessage());
            }

            wp_send_json($this->run());
        })->dispatch();
    }
268197
def register(self, service, name=''):
        
        # expose a sub-factory
        if isinstance(service, ApiFactory):
            self.services[name] = (service.factory, None)

        # expose a module dynamically as a service
        elif inspect.ismodule(service):
            name = name or service.__name__.split('.')[-1]

            # exclude endpoints with patterns
            for obj in vars(service).values():
                endpoint = getattr(obj, 'endpoint', None)
                if isinstance(endpoint, Endpoint) and endpoint.pattern:
                    route = Route('', endpoint.pattern)
                    self.routes.append((route, endpoint))

            self.services[name] = (ModuleService, service)

        # expose a class dynamically as a service
        elif inspect.isclass(service):
            name = name or service.__name__
            self.services[name] = (ClassService, service)

        # expose an endpoint directly
        elif isinstance(getattr(service, 'endpoint', None), Endpoint):
            if service.endpoint.pattern:
                route = Route('', service.endpoint.pattern)
                self.routes.append((route, service.endpoint))
            else:
                self.services[service.endpoint.name] = (service.endpoint, None)

        # expose a scope
        elif isinstance(service, dict):
            for srv in service.values():
                try:
                    self.register(srv)
                except RuntimeError:
                    pass

        # expose a list of services
        elif isinstance(service, list):
            for srv in service:
                try:
                    self.register(srv)
                except RuntimeError:
                    pass

        # expose a service directly
        else:
            raise RuntimeError('Invalid service provide: {0} ({1}).'.format(service, type(service)))
285104
public function register(string $name, Closure $definition)
    {
        $this->registrar->set($name, $definition);
    }
1097835
protected function registerServices()
    {
        foreach ($this->serviceBindings as $key => $value) {
            is_numeric($key)
                    ? $this->app->singleton($value)
                    : $this->app->singleton($key, $value);
        }
    }