Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@rxstack/service-registry

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rxstack/service-registry

RxStack ServiceRegistry Component

latest
Source
npmnpm
Version
0.8.0
Version published
Maintainers
1
Created
Source

The Service Registry

Simple registry component useful for all types of applications.

Installation

npm install @rxstack/service-registry --save

Documentation

  • Usage
  • Exceptions

Usage

A registry object acts as a collection of objects. It allows you to store objects which implement a specific interface.

Each service should implement NamedServiceInterface:

    import {NamedServiceInterface} from '@rxstack/registry';

    export class MyService implements NamedServiceInterface {
      getName(): string {
        return 'service-1';
      }
    }

Here we go:

    import {ServiceRegistry} from '@rxstack/registry';

    const registry = new ServiceRegistry<MyServiceInterface>();
    registry.register(new MyService1());
    registry.register(new MyService2());
    
    registry.has('service-1'); // should return true
    registry.get('service-1'); // should get service instance
    registry.all(); // should retun an array of all registered service
    registry.reset(); // clears all services from registry

Removing a service from the registry is as easy as adding:

// ...
registry.unregister('service-1');
registry.has('service-1'); //should return false

Exceptions

ExistingServiceException is thrown when you try to register a service that is already in the registry.

NonExistingServiceException is thrown when you try to unregister or get a service which is not in the registry.

License

Licensed under the MIT license.

Keywords

rxstack

FAQs

Package last updated on 02 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts