automated-omusubi
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i automated-omusubi

Weekly Downloads

16

Version

0.0.8

License

MIT

Unpacked Size

15.4 kB

Total Files

19

Last publish

Collaborators

  • kojiro.ueda