Skip to content

Implement @LazyInject decorator #92

Open
@guyca

Description

@guyca

This differs from the @LateInject decorator in that the dependency will be resolved the first time it's accessed without needing to call Obsidian.inject(this) explicitly.

API

@Injectable(ApplicationGraph)
class Injected {
  @LazyInject() foo!: Foo;

  constructor() {
    // foo is unresolved
    this.foo.bar(); // foo is resolved on demand
  }
}

Implementation

In order to achieve this behavior, the @LazyInject decorator should probably return a Proxy which will resolve the dependency when it's required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions