Skip to content

Conversation

@AniketDev7
Copy link
Contributor

Implement Lazy Initialization Pattern for Config Handler

Problem

After upgrading to OCLIF v4, we encountered initialization issues with the config handler being initialized upon import, causing failures in the GoCD pipeline environment. This was particularly problematic because plugins that imported but didn't use the config were still triggering initialization.

Solution

Implemented a lazy initialization pattern for the Config class where:

  • Configuration is only initialized when actually needed (when get/set/delete methods are called)
  • The config property is now null by default
  • Added initializeIfNeeded() method to handle lazy initialization
  • Maintained all existing encryption and migration functionality

Key Changes

  1. Modified Config class to use lazy initialization:

    • Constructor no longer initializes config immediately
    • Added initializeIfNeeded() method for on-demand initialization
    • All public methods (get/set/delete/clear) now call initializeIfNeeded()
  2. Documentation:

    • Added comprehensive class-level documentation
    • Restored and enhanced inline comments for better code understanding
    • Added explanatory comments for the lazy initialization pattern

Benefits

  1. Performance: Plugins that import but don't use the config no longer trigger unnecessary initialization
  2. Reliability: Prevents initialization conflicts with OCLIF v4's lifecycle
  3. Maintainability: Clear documentation and comments for future maintenance

Testing

  • Tested in local environment
  • Verified in GoCD pipeline environment
  • Confirmed compatibility with existing plugins
  • Sanity has failed which I am checking

Breaking Changes

None. This is a non-breaking change as all public methods maintain their existing signatures and behavior.

- Remove NODE_ENV check that was causing null config in development
- Update package versions to latest compatible versions
- Add version management script for maintaining dependency consistency
- Fix authentication handler issues with OCLIF v4
- Add lazy initialization pattern to prevent unnecessary config operations
- Initialize config only when methods are actually called
- Add documentation explaining the lazy initialization pattern
- Keep all existing functionality intact
@AniketDev7 AniketDev7 requested a review from a team as a code owner July 24, 2025 10:49
aman19K
aman19K previously approved these changes Jul 24, 2025
@AniketDev7 AniketDev7 merged commit 4118cd2 into development Jul 24, 2025
10 checks passed
@AniketDev7 AniketDev7 deleted the fix/config-singleton-pattern branch July 24, 2025 12:46
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.

3 participants