-
-
Notifications
You must be signed in to change notification settings - Fork 111
refactor: clarify hook service responsibilities and eliminate duplication #4628
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…tion Rename services to reflect their actual responsibilities: - IHookDiscoveryService → IHookRegistrar (registers metadata into Sources) - IHookCollectionService → IHookDelegateBuilder (builds executable delegates) - Update all implementations and references accordingly Eliminate duplication in delegate building: - Add generic BuildGlobalHooksAsync<THookMethod, TContext>() helper - Convert 10 nearly-identical BuildGlobalXXX methods to one-liners - Reduce ~170 lines of duplicate code to ~20 lines This is an internal refactoring with no behavior changes. Eager hook initialization is preserved, and all existing functionality remains intact.
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Add opt-in debug logging to track hook delegate creation: - Log when building global hooks during initialization - Log each hook delegate being created with hook name and type - Log summary count of delegates built per hook type - Inject TUnitFrameworkLogger into HookDelegateBuilder This enables troubleshooting by showing: - Which hooks are being registered - When delegates are created - Total hook counts at startup Users must enable Debug log level to see this output.
Add debug logging to the generated module initializer to track: - Module initializer start/completion - Source generation mode enablement - Assembly reference loading (count and individual assemblies) - Assembly loading failures with error messages The generated code uses GlobalContext.Current.GlobalLogger.LogDebug() which: - Logs to Debug level (opt-in by user) - Works as soon as logger is configured - No-ops early if logger isn't ready yet (defaults to NullLogger) Example output when Debug logging enabled: ``` DEBUG: [ModuleInitializer] TUnit infrastructure initializing... DEBUG: [ModuleInitializer] Source generation mode enabled DEBUG: [ModuleInitializer] Loading 5 assembly reference(s)... DEBUG: [ModuleInitializer] Loading assembly containing: global::MyTests.TestClass DEBUG: [ModuleInitializer] TUnit infrastructure initialized ``` This helps diagnose early initialization issues and understand when assemblies are loaded to trigger module constructors.
Addresses timing issue where module initializers run before the main logger is configured. Implements EarlyBufferLogger that buffers all log messages until the real logger is set, then flushes buffered messages. Changes: - Created EarlyBufferLogger implementing ILogger with ConcurrentQueue - Modified GlobalContext to use EarlyBufferLogger initially - FlushTo() replays buffered logs when real logger is assigned - Debug logging in generated module initializers now works correctly
This was referenced Feb 1, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves code clarity and maintainability in the hook services by:
Changes
1. Renamed Hook Registrar Services
IHookDiscoveryService→IHookRegistrarSourceGenHookDiscoveryService→SourceGenHookRegistrarReflectionBasedHookDiscoveryService→ReflectionHookRegistrarWhy: The old name "Discovery" was ambiguous. The new name "Registrar" clearly indicates these services register hook metadata into
Sourcescollections.2. Renamed Hook Delegate Builder Services
IHookCollectionService→IHookDelegateBuilderHookCollectionService→HookDelegateBuilderWhy: The old name "Collection" was confusing (sounded like it was finding hooks). The new name "DelegateBuilder" clearly indicates it builds executable
Func<>delegates from hook metadata.3. Code Deduplication
BuildGlobalHooksAsync<THookMethod, TContext>()helper methodBefore:
After:
Impact
✅ No behavior changes - Internal refactoring only
✅ No breaking changes - All public APIs unchanged
✅ Builds successfully - Zero warnings or errors
✅ Same performance - Eager initialization preserved
✅ Better maintainability - Clear responsibilities, less duplication
Test Plan