Skip to content

Add observer feature for Scope lifecycle tracking#274

Open
yhartanto wants to merge 3 commits intouber:mainfrom
yhartanto:feature/scope-observer
Open

Add observer feature for Scope lifecycle tracking#274
yhartanto wants to merge 3 commits intouber:mainfrom
yhartanto:feature/scope-observer

Conversation

@yhartanto
Copy link

This commit introduces a new observer pattern for Motif scopes that allows tracking of scope initialization and factory method invocations.

Key features:

  • New @scope(enableObserver = true) annotation parameter
  • Observer interface with lifecycle event methods:
    • onScopeInitializing - called when scope is constructed
    • onProvideStart - called before factory method execution
    • onProvideComplete - called after factory method execution
  • MotifObserver registry for managing observers (thread-safe)
  • Environment variable control: observer code only generated when MOTIF_OBSERVE=1 or MOTIF_OBSERVE=True is set at compile time
  • Comprehensive test coverage with T079_observer test case

Benefits:

  • Zero runtime overhead when observer is not enabled
  • Useful for debugging, profiling, and monitoring dependency injection
  • Minimal API surface with simple enable/disable mechanism

All 343 tests passing.

Description:

Related issue(s):

yhartanto and others added 3 commits March 24, 2026 21:24
This commit introduces a new observer pattern for Motif scopes that allows
tracking of scope initialization and factory method invocations.

Key features:
- New @scope(enableObserver = true) annotation parameter
- Observer interface with lifecycle event methods:
  * onScopeInitializing - called when scope is constructed
  * onProvideStart - called before factory method execution
  * onProvideComplete - called after factory method execution
- MotifObserver registry for managing observers (thread-safe)
- Environment variable control: observer code only generated when
  MOTIF_OBSERVE=1 or MOTIF_OBSERVE=True is set at compile time
- Comprehensive test coverage with T079_observer test case

Benefits:
- Zero runtime overhead when observer is not enabled
- Useful for debugging, profiling, and monitoring dependency injection
- Minimal API surface with simple enable/disable mechanism

All 343 tests passing.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Apply automatic code formatting to meet project style guidelines.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fix google-java-format violations in observer feature files.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1 participant