Skip to content

[WIP] 带参数的类注入 #3

@hyj1991

Description

@hyj1991

需求

import { Injectable, ScopeEnum } from "@artus/injection";

@Injectable({
  id: 'foo',
  scope: ScopeEnum.EXECUTION
})
export class Foo {
  #name: string;
  constructor(name: string) {
   this.#name = name;
  }

  say() {
    console.log(this.#name);
  }
}

每个 Execution 生命周期中实例化Foo 时如何通过 container 传入构造函数需要的参数,比如:

import { Inject } from "@artus/injection";

export class Bar {
  @Inject('foo')
  private foo;

  say() {
    this.foo.say();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions