di-stateless
v1.0.0
Published
Transient services similar to ASP.Net Core. A service that is created every time it is requested from a service container
Downloads
86
Maintainers
Readme
di-stateless
Transient services similar to ASP.Net Core. A service that is created every time it is requested from a service container
Usage
import { stateless } from 'di-stateless';
const TransientService = stateless(
class {
randomId = randomString();
constructor() {
console.log("TransientService CTOR");
}
methodFoo = () => this.randomId;
methodBaz = () => this.randomId;
methodBar = () => this.randomId;
entry = () => console.log({
foo: this.methodFoo(),
bar: this.methodBar(),
baz: this.methodBaz(),
});
}
);
const service = new TransientService();
service.entry(); // { foo: "ndjol", bar: "ndjol", baz: "ndjol" }
service.randomId = "not-random-id";
service.entry(); // { foo: "c2wiyf", bar: "c2wiyf", baz: "c2wiyf" }