migrate-static-to-wrapper

Replace static dependency call sites with injected wrapper abstractions across a bounded C# scope.

Updated Jul 20, 2026
One-click install
npx skills add https://github.com/Netcodr81/kinetic-reports --skill migrate-static-to-wrapper-netcodr81
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: migrate-static-to-wrapper
Source: https://github.com/Netcodr81/kinetic-reports/tree/main/.github/skills/migrate-static-to-wrapper
Command: npx skills add https://github.com/Netcodr81/kinetic-reports --skill migrate-static-to-wrapper-netcodr81

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Static calls like DateTime.UtcNow and File.ReadAllText make .NET code untestable and hard to control in unit tests. This Skill performs codemod-style bulk replacement of those static call sites with injected abstractions such as TimeProvider or IFileSystem, adding constructor injection and updating tests, all within a bounded file, project, or namespace scope. ## Core Features & Use Cases - Mechanical call-site replacement: Migrates DateTime.Now/UtcNow to TimeProvider, File.* to IFileSystem, and similar statics, preserving DateTimeKind and surrounding code structure. - Constructor injection and ambient seams: Adds constructor or primary-constructor parameters following existing naming conventions, and applies an ambient static seam pattern for static classes that cannot receive injection. - Test updates and build verification: Updates unit tests to use FakeTimeProvider or MockFileSystem, verifies DI registration, and runs dotnet build to confirm the migration compiles. - Use Case: Migrate DateTime.UtcNow to TimeProvider across one project, with FakeTimeProvider injected into the affected unit tests, while leaving other namespaces untouched for a later incremental pass. ## Quick Start Migrate all DateTime.UtcNow call sites in the Services project to TimeProvider, add constructor injection, and update the corresponding 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. Use .UtcDateTime rather than .DateTime so the resulting DateTime keeps Kind == Utc and avoids silent behavioral changes.

How to migrate File.ReadAllText to IFileSystem in .NET?▼

Replace File.ReadAllText(path) with _fileSystem.File.ReadAllText(path), add using System.IO.Abstractions, and inject IFileSystem via the constructor. Verify the System.IO.Abstractions NuGet package is referenced and registered in Program.cs or Startup.cs first.

Can static classes receive constructor injection in C#?▼

No, static classes cannot have instance constructors or fields. 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, with those tests excluded from parallel execution.

What test double replaces TimeProvider in unit tests?▼

Use FakeTimeProvider from the Microsoft.Extensions.TimeProvider.Testing NuGet package. For IFileSystem, use MockFileSystem from System.IO.Abstractions.TestingHelpers, and use mocks or hand-rolled fakes for custom wrappers.

When should I not migrate static call sites with this approach?▼

Do not migrate when no wrapper or abstraction exists yet, when you only want to detect statics rather than replace them, or when migrating between test frameworks. Generate and register the wrapper in DI first, then migrate one project or namespace at a time.