migrate-static-to-wrapper

Replace static dependency call sites with injected wrappers or built-in abstractions in C# code.

1|Updated Jul 27, 2026
One-click install
npx skills add https://github.com/FittyAr/Cardscape --skill migrate-static-to-wrapper-fittyar
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: migrate-static-to-wrapper
Source: https://github.com/FittyAr/Cardscape/tree/main/.agents/skills/migrate-static-to-wrapper
Command: npx skills add https://github.com/FittyAr/Cardscape --skill migrate-static-to-wrapper-fittyar

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Static calls like DateTime.UtcNow and File.ReadAllText make C# code untestable and tightly coupled. This Skill performs codemod-style bulk replacement of those call sites with injected abstractions such as TimeProvider or IFileSystem, including constructor injection and test updates, within a bounded scope. ## Core Features & Use Cases - Bulk call-site replacement: Migrates DateTime.Now/UtcNow to TimeProvider, File.* to IFileSystem, and similar statics across a file, project, or namespace. - Constructor injection handling: Adds the new dependency via traditional or primary constructors, and applies an ambient-context seam for static classes that cannot receive injection. - Test updates and verification: Updates unit tests to use FakeTimeProvider or MockFileSystem, verifies DI registration, and runs dotnet build to confirm the migration compiles. - Use Case: You want to make an OrderProcessor class testable. Run the migration on its project to replace every DateTime.UtcNow with TimeProvider.GetUtcNow(), inject TimeProvider into the constructor, and update its tests to use FakeTimeProvider. ## Quick Start Migrate all DateTime.UtcNow call sites in the Services project to TimeProvider, add constructor injection, and update the affected unit tests to use FakeTimeProvider.

Frequently Asked Questions about migrate-static-to-wrapper

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace DateTime.UtcNow with TimeProvider in C#?▼

Replace DateTime.UtcNow with _timeProvider.GetUtcNow().UtcDateTime and inject TimeProvider through the class constructor. Using .UtcDateTime preserves the original DateTimeKind.Utc, avoiding silent behavioral changes.

How to migrate static File calls to IFileSystem for testability?▼

Replace calls like File.ReadAllText(path) with _fileSystem.File.ReadAllText(path) after adding the System.IO.Abstractions package and registering IFileSystem in DI. Update tests to use MockFileSystem from System.IO.Abstractions.TestingHelpers.

Can static classes receive constructor injection in C#?▼

No, static classes cannot have instance constructors. Use an ambient-context seam instead: a public static settable property defaulting to the real implementation, overridden in tests and always restored in a finally block.

Why does my TimeProvider migration change DateTime behavior?▼

TimeProvider.GetUtcNow() returns DateTimeOffset, and its .DateTime property yields Kind.Unspecified. Use .UtcDateTime for former DateTime.UtcNow sites and .LocalDateTime for former DateTime.Now sites to preserve the original DateTimeKind.

When should I not use this static-to-wrapper migration approach?▼

Do not use it when no wrapper or abstraction exists yet, when you only want to detect statics rather than migrate them, or when migrating between test frameworks. Generate or register the wrapper first, then run the migration.