New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vorarbeiter

Package Overview
Dependencies
Maintainers
0
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vorarbeiter

A simple service container

  • 1.0.3
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

A simple service container

  1. Create some services:
interface Car {
  getDriverName(): string;
}

class CarImpl implements Car {
  constructor(private readonly driver: Driver) {}
  getDriverName() {
    return this.driver.getName();
  }
}

interface Driver {
  getName(): string;
}

class DriverImpl implements Driver {
  getName() {
    return "Michael Schumacher";
  }
}
  1. Explain to Service Container how to create services, use factories for this:
class CarFactory implements ServiceFactory {
  create(container: ServiceContainer): CarImpl {
    const driver = container.get("driver");
    return new CarImpl(driver);
  }
}

class DriverFactory implements ServiceFactory {
  create(container: ServiceContainer): DriverImpl {
    return new DriverImpl();
  }
}
  1. Create services Specification:
const spec = new Map();

spec.set("car", {
    factory: new CarFactory()
});

spec.set("driver", {
    factory: new DriverFactory()
});
  1. Create Service Container with this Specification:
const serviceContainer = new ServiceContainer(spec);
  1. Get some service and call its method:
const car: Car = serviceContainer.get("car");

console.log(car.getDriverName());
  1. Get string "Michael Schumacher".

Keywords

FAQs

Package last updated on 12 Jan 2025

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc