Skip to content

bug(workspace): AccountEntity used in WorkspaceViewModel + IServiceProvider service locator #42

@jaybarden1

Description

@jaybarden1

Problem

Workspace/WorkspaceViewModel.cs has two rule violations:

1. AccountEntity used directly in ViewModel

AccountEntity (a persistence model) is imported and used in MapToViewModel(AccountEntity entity). Per onedrive-viewmodels.md: "*Entity types are never used in ViewModels or views. Mapping from *Entity → domain model occurs in the service layer."

Fix: Introduce a service/factory that returns IReadOnlyList<OneDriveAccount> (domain models). WorkspaceViewModel consumes domain models only. Remove MapToViewModel(AccountEntity) from the ViewModel.

2. IServiceProvider injected (service locator pattern — banned)

IServiceProvider is injected and _serviceProvider.GetRequiredService<AddAccountWizardViewModel>() is called inside the ViewModel. Per onedrive-di.md: "Service locator pattern — never inject IServiceProvider into business logic."

Fix: Replace IServiceProvider injection with Func<AddAccountWizardViewModel> wizardFactory and call wizardFactory() in ExecuteOpenAddAccountWizard.

3. Hardcoded real-looking email addresses

Design-time sample data at lines ~176–224 includes jason@outlook.com, jason.barden@work.com, jane@dev.io, jason@sideproject.io. Even for design-time data, real-looking PII should not be committed to source. Replace with obviously fictional values (user@example.com, alice@example.com).

Rule reference

@.claude/rules/onedrive-viewmodels.md — Domain model isolation; @.claude/rules/onedrive-di.md — What is banned

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingui

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions