npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lucastraba/service-manager

v1.0.0

Published

A simple IoC container for TypeScript

Downloads

17

Readme

Service Manager

The Service Manager is a simple schema-based IoC (Inversion of Control) container for TypeScript. It provides a way to manage dependencies and services in your application, making it easier to write modular, testable, and maintainable code.

Features

  • Dependency Injection Made Easy: The Service Manager automatically resolves and injects dependencies based on simple service definition schemas
  • Instance Management: Swap injections and arguments easily by defining them in the service definition schema
  • Singletons galore: All your services will be singletons, no need to worry about misplacing your state
  • Post-build Actions: Define your initialization actions directly in the schema
  • Lazy Loading: Service modules are imported asynchronously on-demand
  • Type Safety: The Service Manager has been meticulously developed to ensure maximum type safety and autocompletion
  • Lightweight: Did you know the Service Manager weighs only 6 kB gzipped? It's true!
  • Zero Dependencies: The Service Manager has no dependencies, so you can expect it to work even if all other libraries collapse

Getting Started

  1. Install the Service Manager package:

    • Using npm
    npm install service-manager
    • Using pnpm
    pnpm add service-manager
    • Using yarn
    yarn add service-manager
  2. Define your service classes:

    // MyService.ts
    export default class MyService {
      constructor(private readonly myDependency: MyDependency) {}
    
      // Service methods...
    }
    
    // MyDependency.ts
    export default class MyDependency {
      // Dependency methods...
    }
    
    // MySecondDependency.ts
    export default class MySecondDependency {
      // Dependency methods...
    }
  3. Create a map of your services and instances (if you need multiple instances of the same service):

    // services.type.ts
    export type Services = {
      MyService: MyService;
      MyDependency: MyDependency;
      MySecondDependency: MySecondDependency;
    };
    export type Instances = {
      myOtherServiceInstance: MyService;
    };
  4. Create a service definition file:

    // serviceDefinitions.ts
    import type { ServiceDefinition } from 'service-manager';
    import type { Services, Instances } from './services.type';
    
    const serviceDefinitions: ServiceDefinition<Services, Instances>[] = [
      {
        serviceClassName: 'MyService',
        serviceInjections: [{ serviceInstanceName: 'MyDependency' }],
        pathToService: async () => import('./MyService'),
      },
      {
        serviceClassName: 'MyDependency',
        pathToService: async () => import('./MyDependency'),
      },
      {
        serviceClassName: 'MySecondDependency',
        pathToService: async () => import('./MySecondDependency'),
      },
      {
        serviceClassName: 'MyService',
        serviceInstanceName: 'myOtherServiceInstance',
        serviceInjections: [{ serviceInstanceName: 'MySecondDependency' }],
        pathToService: async () => import('./MyService'),
      },
    ];
    
    export default serviceDefinitions;
  5. Initialize the Service Manager:

    // index.ts
    import { ServiceManager } from 'service-manager';
    import serviceDefinitions from './serviceDefinitions';
    
    const serviceManager = new ServiceManager<Services, Instances>({
      serviceDefinitions,
    });
  6. Load and use services:

    // index.ts
    async function main() {
      const myService = await serviceManager.loadService('MyService');
      // Use myService...
      const myServiceInstance = await serviceManager.loadService(
        serviceManager.SERVICES.myServiceInstance
      );
      // Use myServiceInstance...
      const [myDependency, mySecondDependency] =
        await serviceManager.loadServices([
          'MyDependency',
          'MySecondDependency',
        ]);
      // Use myDependency and mySecondDependency...
    }
    
    main();

Additional Information and Examples

For additional information and examples, please refer to the ServiceManager class TSDocs section.

API Reference

For more information about the API, you can check the TSDocs section.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the MIT License © Lucas Traba.