Skip to content

[Maintainability] Manager MainWindow.xaml.cs — CreateMainViewModel is 60-line composition root in View code-behind #649

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Warning

File: src/Servy.Manager/Views/MainWindow.xaml.cs
Lines: 48–109

Description:
CreateMainViewModel() is a 60-line composition root inside the View's code-behind. It hardwires the entire dependency graph: AppDbContext, DapperExecutor, ProtectedKeyProvider, SecureData, ServiceRepository, ServiceManager, FileDialogService, MessageBoxService, HelpService, and more. The View knows about infrastructure types (AppDbContext, DapperExecutor, SQLiteDbInitializer) that have no business in a UI layer. Replacing any dependency requires modifying the View. The same pattern exists in Servy/Views/MainWindow.xaml.cs.

Suggested fix:
Move composition to App.xaml.cs or a dedicated Bootstrapper/DI container. The Window should receive a pre-built MainViewModel, not build it.

Metadata

Metadata

Assignees

Labels

refactorChanges that improve structure, readability, or maintainability without altering external behavior.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions