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

Document application / component lifecycle #981

Open
str4d opened this issue Mar 8, 2025 · 1 comment
Open

Document application / component lifecycle #981

str4d opened this issue Mar 8, 2025 · 1 comment

Comments

@str4d
Copy link

str4d commented Mar 8, 2025

One of the things I'm having trouble figuring out is how components fit into the overall application lifecycle. After lots of digging into the code, I think the application lifecycle is roughly this:

This means that AFAICT the methods on a component are always called in this order:

  • MyComponent::new (or whatever the app chooses)
  • Component::after_config
  • Component::register_dependency
    • MyComponent::init_foobar etc. if using the derive.
  • MyComponent::some_method by a command after fetching it via APP.state().components().get_by_id(..)
  • Component::before_shutdown

If this order is reliable, it would be useful to document it in places where a new developer is going to find it (currently the docs suggest this should be the Component trait, but it could also be the component module; in either case the Component derive should have documentation that links to it).

@str4d
Copy link
Author

str4d commented Mar 8, 2025

The main thing the lack of documentation tripped me up on is the fact that components need basically all of their internal state to be either Optioned or Defaulted, and then filled in or altered after the config is loaded (instead of loading the config, and then constructing each component from that config).

The framework components (Terminal and Tracing) by comparison don't actually integrate in this way: they call the custom Application::term_colors and Application::tracing_config methods in between CLI argument parsing and component graph registration. These core components are constructed from a compiled-in config, but the config loaded from disk cannot influence them until after Component::register_dependency (i.e. manually during command run) instead of during Component::after_config.

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

1 participant