1.0.0 • Published 5 years ago
cmdo-server v1.0.0
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
1.0.0
5 years ago
1.0.0-beta.10
5 years ago
1.0.0-beta.2
5 years ago
1.0.0-beta.1
5 years ago
1.0.0-beta.0
5 years ago