Improved omusubi. You do not need to register.
important
You must enable TypeScript compiler options.
{
"compilerOptions": {
// ...
"experimentalDecorators": true,
"emitDecoratorMetadata": true
// ...
}
}
import {named, binding} from "automated-omusubi";
@named
class Injectable {
x = "foo";
}
class Injected {
@binding
foo!: Injectable;
func() {
return this.foo; // <-- Injectable instance.
}
}
console.log(new Injected().func());
It can be used in dependency inversion principle
import {namedWith, bindBy} from "automated-omusubi";
abstract class AbstractInjectable {
x = "bar";
}
@namedWith(AbstractInjectable)
class Injectable extends AbstractInjectable {
y = "foo";
}
class Injected {
@bindBy(AbstractInjectable)
foo!: AbstractInjectable;
func() {
return this.foo; // <-- Injectable instance.
}
}
console.log(new Injected().func());
import {register, bind} from "automated-omusubi";
class Injectable {
y = "foo";
z: string;
constructor(z: string) {
this.z = z;
}
}
class Injected {
@bind
foo!: Injectable;
func() {
return this.foo; // <-- Injectable instance.
}
}
register(new Injectable("bar")).as(Injectable);
console.log(new Injected().func());