npm.io
0.0.9 • Published 2 years ago

automated-omusubi

Licence
MIT
Version
0.0.9
Deps
1
Size
15 kB
Vulns
0
Weekly
0

automated-omusubi

Improved omusubi. You do not need to register.

how to use

important

You must enable TypeScript compiler options.

{
  "compilerOptions": {
    // ...
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
    // ...
  }
}

automated injection

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());

identifier specified injection

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());

identifier specified injection and explicitly instance registration

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());