Loading...
Loading...
Mechanically replace static dependency call sites with wrapper or built-in abstraction calls across a bounded scope (file, project, or namespace). Performs codemod-style bulk replacement of DateTime.UtcNow to TimeProvider.GetUtcNow(), File.ReadAllText to IFileSystem, and similar transformations. Adds constructor injection parameters and updates DI registration. USE FOR: replace DateTime.UtcNow with TimeProvider, replace DateTime.Now with TimeProvider, migrate static calls to wrapper, bulk replace File.* with IFileSystem, codemod static to injectable, add constructor injection for time provider, mechanical migration of statics, refactor DateTime to TimeProvider, swap static for injected dependency, convert static calls to use abstraction, replace statics in a class, migrate one file to TimeProvider, scoped migration, update call sites. DO NOT USE FOR: detecting statics (use detect-static-dependencies), generating wrappers (use generate-testability-wrappers), migrating between test frameworks.
npx skill4agent add dotnet/skills migrate-static-to-wrappergenerate-testability-wrappersDateTime.UtcNowTimeProvider.GetUtcNow()File.*IFileSystem.File.*generate-testability-wrappersdetect-static-dependencies| Input | Required | Description |
|---|---|---|
| Static pattern | Yes | What to replace (e.g., |
| Replacement abstraction | Yes | What to use instead (e.g., |
| Scope | Yes | File path, project (.csproj), namespace, or directory to migrate |
| Injection strategy | No | |
TimeProviderMicrosoft.Bcl.TimeProviderSystem.IO.AbstractionsProgram.csStartup.cs.csobj/bin/TimeProviderIFileSystem| Category | Original | DI replacement |
|---|---|---|
| Time | | |
| Time | | |
| Time | | |
| Time | | |
| File | | |
| File | | |
| File | | |
| File | | |
| Env | | |
| Console | | |
| Process | | |
public class OrderProcessor(ILogger<OrderProcessor> logger, TimeProvider timeProvider)private readonly_camelCasem_camelCaseusing| Abstraction | Using directive |
|---|---|
| None (in |
| |
| |
| Custom wrappers | |
TimeProvidernew FakeTimeProvider()Microsoft.Extensions.TimeProvider.TestingIFileSystemnew MockFileSystem()System.IO.Abstractions.TestingHelpersnew Mock<IWrapperName>()dotnet build <project.csproj>usingdotnet add package <name>## Migration Summary
**Pattern**: DateTime.UtcNow → TimeProvider.GetUtcNow()
**Scope**: MyProject/Services/
### Files Modified (production)
| File | Call Sites Replaced | Injection Added |
|------|--------------------:|:----------------|
| OrderProcessor.cs | 3 | Yes (constructor) |
| NotificationService.cs | 1 | Yes (primary ctor) |
### Files Modified (tests)
| File | Change |
|------|--------|
| OrderProcessorTests.cs | Added FakeTimeProvider parameter |
### Remaining (out of scope)
- MyProject/Legacy/ — 8 call sites not migrated (different namespace)using| Pitfall | Solution |
|---|---|
| Replacing statics in test code | Only replace in production code; tests should use fakes/mocks |
| Breaking static classes | Static classes can't have constructors — use ambient context for these |
Missing | Add |
| Replacing in expression-bodied members without updating return type | |
| Migrating too much at once | Stick to the defined scope — one project or namespace per run |
| Forgetting DI registration | Always verify |