migrate-static-to-wrapper

Replace static dependency call sites with injected wrapper abstractions across C# codebases.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Static calls like DateTime.UtcNow and File.ReadAllText make .NET code untestable and tightly coupled. Manually replacing every call site, adding constructor injection, and updating tests is tedious and error-prone across large projects. ## Core Features & Use Cases - Codemod-Style Bulk Replacement: Mechanically converts static calls (DateTime.UtcNow, File., Environment., Console.*) to injected abstractions like TimeProvider and IFileSystem within a bounded scope. - Constructor Injection Automation: Adds dependency parameters to traditional or primary constructors following existing naming conventions, and verifies DI registration in Program.cs or Startup.cs. - Test File Updates: Updates test instantiations with fakes such as FakeTimeProvider and MockFileSystem, then verifies the migration with dotnet build. - Use Case: Migrate DateTime.UtcNow to TimeProvider.GetUtcNow() across one project, with constructor injection added and tests updated to use FakeTimeProvider. ## Quick Start Replace all DateTime.UtcNow calls with TimeProvider.GetUtcNow() in the Services project and add constructor injection to the affected classes.

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 each DateTime.UtcNow call with _timeProvider.GetUtcNow().DateTime and inject TimeProvider via the class constructor. TimeProvider is built into .NET 8+, or available via the Microsoft.Bcl.TimeProvider NuGet package for earlier targets.

How to migrate File.ReadAllText to IFileSystem for testability?

Replace File.ReadAllText(path) with _fileSystem.File.ReadAllText(path) after injecting IFileSystem from the System.IO.Abstractions NuGet package. In tests, substitute MockFileSystem from System.IO.Abstractions.TestingHelpers.

Does TimeProvider work with older .NET versions?

TimeProvider is built into .NET 8 and later. For earlier target frameworks, add the Microsoft.Bcl.TimeProvider NuGet package to use the same abstraction.

What test double replaces TimeProvider in unit tests?

Use FakeTimeProvider from the Microsoft.Extensions.TimeProvider.Testing NuGet package. It lets tests control and advance time deterministically instead of relying on the system clock.

When should I not migrate static calls to wrappers?

Skip migration when no wrapper or abstraction exists yet, when the goal is only detecting statics, or when the class is static and cannot accept constructor injection. Static classes require an ambient context approach instead.