Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement @LazyInject decorator #92

Open
guyca opened this issue May 2, 2023 · 0 comments
Open

Implement @LazyInject decorator #92

guyca opened this issue May 2, 2023 · 0 comments
Labels
api enhancement New feature or request

Comments

@guyca
Copy link
Collaborator

guyca commented May 2, 2023

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.

@guyca guyca added enhancement New feature or request api labels May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant