cmdo-server

Back end server written in nodejs.

Usage no npm install needed!

<script type="module">
  import cmdoServer from 'https://cdn.skypack.dev/cmdo-server';
</script>

README

Inverse

A simple dependency service.

Services

Services is where you create your container tokens.

import { token } from "cmdo-inverse";

type Constructor = {
  new (): Country;
}

export type Country = {
  greet(): string;
}

export type CountryToken = Token<Constructor, Country>;

Providers

Providers are implementation details for the injectable services and are registered with the container.

import { Country } from "country";

export class USA implements Country {
  greet(): string {
    return "Howdy";
  }
}

export class UK implements Country {
  greet(): string {
    return "Hello";
  }
}

Tokens

import { CountryToken } from "services/country";

export type Countries = {
  usa: CountryToken;
  uk: CountryToken;
}

Container

Inverse container consists of a list of injectable transient and singleton tokens. A token consists of a constructor and type definition.

import { Container } from "cmdo-inverse";
import { Tokens } from "tokens";

export const container = new Container<Tokens>();

Register Dependency Providers

import { container } from "container";
import { USA, UK } from "countries";

container
  .register("usa", USA)
  .register("uk", UK);

Sample Usage

import { container } from "container";

export class Sample {
  constructor(public country = container.resolve("usa")) {};
}

const sample = new Sample();

// typeof sample.country === Country