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

Allow for easier debug of dependency graph #960

Open
deebloo opened this issue May 5, 2024 · 3 comments
Open

Allow for easier debug of dependency graph #960

deebloo opened this issue May 5, 2024 · 3 comments

Comments

@deebloo
Copy link
Member

deebloo commented May 5, 2024

To help make it easier to debug injectors and their dependencies there should be an optional API that will describe how a particular series was resolved.

Initial thought it is export an additional injectDebug() function. (To make it tree shakeable)

This function would log the dependency tree for the injected service.

Cc @Phoscur

@Phoscur
Copy link
Contributor

Phoscur commented May 5, 2024

Initial thought it is export an additional injectDebug() function. (To make it tree shakeable)

That sounds easiest to maintain, but it might be limited by or breaking encapsulation in places?

Replacing the implementation of entire core files would be a potential alternative I've seen in other projects. Applying that here it would mean: Copy injector.ts: injector.debug.ts, sprinkle in many console.debug statements or save debug info into arrays to be inspected later ... e.g. especially where undefined is returned. Although it is worse to maintain (code duplication), it does not tempt you to break encapsulation or rather gives you full freedom of debuggability.

@deebloo
Copy link
Member Author

deebloo commented May 5, 2024

Another though would be to add the ability to pass a debug function to inject(). Inject(Service, { debug })

@Phoscur
Copy link
Contributor

Phoscur commented May 18, 2024

One debugging usecase, counting instances:

// in some element:
static providers = [{ provide: EconomyService, use: EconomyService }]; // force a new instance for each element

// then I need to decorate my service like this to debug the amount of actual instances created (and alive?!):
@injectable
export class EconomyService {
  static count = 0;
  constructor() {
    EconomyService.count++;
    console.log('E', EconomyService.count);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants