Skip to content

refactor: migrate to DI container and ILogger<T>#7

Merged
Wintersta7e merged 11 commits intomainfrom
refactor/di-logging-migration
Mar 5, 2026
Merged

refactor: migrate to DI container and ILogger<T>#7
Wintersta7e merged 11 commits intomainfrom
refactor/di-logging-migration

Conversation

@Wintersta7e
Copy link
Owner

Summary

  • Replace static Serilog.Log.Logger with dependency-injected Microsoft.Extensions.Logging.ILogger<T> across the entire codebase
  • Introduce full DI container (Microsoft.Extensions.DependencyInjection) for Core, UI, and CLI projects
  • Serilog remains as the logging provider behind M.E.Logging, configured only in 2 composition roots (App.axaml.cs, Program.cs)
  • Add AddFlowForgeCore() extension method as single source of truth for Core service registration
  • All 11 node constructors receive typed ILogger<T> via ILoggerFactory in NodeRegistry.CreateDefault()
  • Tests migrated to NullLogger<T>.Instance — zero Serilog boilerplate
  • Comprehensive review fixes: null guards, diagnostic logging, startup/shutdown safety, error handling improvements
  • 7 new DI registration tests, 243 total tests passing, 0 warnings

Changes (41 files, +604 -240)

Commit Scope
0543d1c Migrate Core to M.E.Logging and DI
835900d Migrate tests to NullLogger<T>
50f572e Migrate UI and CLI to DI composition roots
efe81a4 Fix ServiceProvider disposal, inject EditorViewModel via DI
1705e7f Harden Core DI registration (explicit factory, XML docs)
d7d3210 Add null guards and diagnostic logging to all nodes
5722245 Harden App startup, shutdown, and DI registration
f19da83 Inject IServiceProvider and IDialogService into MainWindowViewModel
f5ff3bf Improve error handling in AppSettingsManager, picker, CLI
4b6442c Add DI registration tests for AddFlowForgeCore
699b27f Bump version to 1.2.0

- Replace Serilog with Microsoft.Extensions.Logging.Abstractions in Core
- Add ILogger<T> constructor injection to all 11 node classes
- Migrate PipelineRunner and AppSettingsManager to ILogger<T>
- Update NodeRegistry.CreateDefault to accept ILoggerFactory
- Create ServiceCollectionExtensions for DI registration
- Add M.E.DI/Logging packages to UI, CLI, and Tests projects
- Suppress CA1848/CA1873 in Core (deferred to future optimization)

Co-Authored-By: Rooty
- Hook ShutdownRequested to dispose ServiceProvider (flushes Serilog)
- Constructor-inject EditorViewModel instead of service locator

Co-Authored-By: Rooty
Use explicit factory registration for AppSettingsManager to avoid
multi-constructor DI ambiguity (H4). Add XML documentation documenting
registrations, lifetimes, and ILoggerFactory prerequisite (M5).

Co-Authored-By: Rooty
Add ArgumentNullException.ThrowIfNull to all 11 node constructors,
NodeRegistry.CreateDefault, and PipelineRunner constructor (H5). Add
LogDebug in Configure methods and LogWarning on error paths for the
7 nodes that had unused logger fields (M1).

Co-Authored-By: Rooty
Replace null! Services property with guarded property that throws
descriptive InvalidOperationException on DI failure (C1). Surface
settings load failures in ExecutionLog.Summary (C2). Change
EditorViewModel to singleton to match its actual captive lifetime (H1).
Wrap shutdown disposal in try-catch with Log.CloseAndFlush (H3).
Register IDialogService in DI container (M2).

Co-Authored-By: Rooty
Replace App.Services service locator with constructor-injected
IServiceProvider for PipelineRunner resolution (H2). Replace
new DialogService() with constructor-injected IDialogService (M2).
Add null guards to all constructor parameters.

Co-Authored-By: Rooty
Replace bare catch block in AppSettingsManager.SaveAsync with logged
warning (M4). Add diagnostic comments to ConfigFieldTemplateSelector
picker catch blocks (M3). Move GetRequiredService above try block in
CLI so DI failures aren't caught as pipeline errors (M6). Add comments
explaining await using disposal mechanism (M7).

Co-Authored-By: Rooty
Verify all services resolve correctly and have expected lifetimes.
Test that missing ILoggerFactory throws descriptive error (C3).

Co-Authored-By: Rooty
Co-Authored-By: Rooty
@Wintersta7e Wintersta7e merged commit a46957a into main Mar 5, 2026
1 check passed
@Wintersta7e Wintersta7e deleted the refactor/di-logging-migration branch March 5, 2026 00:20
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