Seams.Analyzers 2.0.2

dotnet add package Seams.Analyzers --version 2.0.2
                    
NuGet\Install-Package Seams.Analyzers -Version 2.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Seams.Analyzers" Version="2.0.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Seams.Analyzers" Version="2.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Seams.Analyzers">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Seams.Analyzers --version 2.0.2
                    
#r "nuget: Seams.Analyzers, 2.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Seams.Analyzers@2.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Seams.Analyzers&version=2.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Seams.Analyzers&version=2.0.2
                    
Install as a Cake Tool

Seams.Analyzers

CI NuGet

A Roslyn analyzer library that detects code patterns blocking "seams" in legacy code, based on Michael Feathers' Working Effectively with Legacy Code.

Use Cases

1. AI-Assisted Development

When SEAM rules are configured as warnings or errors, AI coding assistants (GitHub Copilot, Claude, Cursor, Windsurf, etc.) read build failures and adapt their code generation to avoid untestable patterns.

How It Works
Developer Request → AI Generation → Analyzer Feedback → AI Iteration → Testable Code
  1. AI generates code with a hard dependency (e.g., new EmailService())
  2. Build fails with SEAM001: Direct instantiation of concrete type 'EmailService'
  3. AI reads this feedback and regenerates using dependency injection
  4. Resulting code is testable from the start
Traditional Workflow With Analyzers
Write code → Analyze → Refactor Configure rules → AI generates → Testable code
Fix problems after creation Prevent problems during generation
Setup

<PropertyGroup>
  <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

2. Legacy Code Refactoring

When working with legacy code, this analyzer helps you identify where to create seams so you can test a class. By detecting the 18 anti-patterns that block testability, you can systematically refactor code to introduce dependency injection points, extract interfaces, and break hard dependencies—making previously untestable code testable.

What are Seams?

A seam is a place where you can alter behavior in your program without editing in that place. Seams are essential for testing because they allow you to substitute dependencies, mock behaviors, and isolate code under test.

This analyzer identifies 18 anti-patterns (SEAM001-SEAM018) across 5 categories that hinder testability by blocking seams.

Installation

dotnet add package Seams.Analyzers

Or via Package Manager:

Install-Package Seams.Analyzers

Diagnostic Rules

Default Severity Levels

Not all rules are enabled by default. This follows the Principle of Least Astonishment (POLA) - rules that may produce many warnings in typical codebases are disabled by default to avoid overwhelming users on first installation.

Severity Meaning Rules
Warning Enabled, likely issues SEAM003, SEAM012, SEAM013, SEAM014, SEAM016
Info Enabled, suggestions SEAM001, SEAM005, SEAM006, SEAM007, SEAM015, SEAM017, SEAM018
Disabled Opt-in only SEAM002, SEAM004, SEAM008, SEAM009, SEAM010, SEAM011

To enable disabled rules, add to your .editorconfig:

# Enable specific disabled rules
dotnet_diagnostic.SEAM002.severity = suggestion
dotnet_diagnostic.SEAM004.severity = suggestion
dotnet_diagnostic.SEAM008.severity = suggestion
dotnet_diagnostic.SEAM009.severity = suggestion
dotnet_diagnostic.SEAM010.severity = suggestion
dotnet_diagnostic.SEAM011.severity = suggestion

Direct Dependencies

Rule Description Default
SEAM001 Direct instantiation of concrete types Info
SEAM002 Concrete type in constructor parameter Disabled
SEAM003 Service locator pattern usage Warning

Static Dependencies

Rule Description Default
SEAM004 Static method calls (File, Console, etc.) Disabled
SEAM005 DateTime.Now/UtcNow usage Info
SEAM006 Guid.NewGuid() usage Info
SEAM007 Environment.GetEnvironmentVariable Info
SEAM008 Static property access (ConfigurationManager) Disabled

Inheritance Blockers

Rule Description Default
SEAM009 Sealed class prevents inheritance Disabled
SEAM010 Non-virtual method prevents override Disabled
SEAM011 Complex private method (50+ lines) Disabled

Global State

Rule Description Default
SEAM012 Singleton pattern implementation Warning
SEAM013 Static mutable field Warning
SEAM014 Ambient context (HttpContext.Current, etc.) Warning

Infrastructure Dependencies

Rule Description Default
SEAM015 Direct file system access Info
SEAM016 Direct HttpClient creation Warning
SEAM017 Direct database connection creation Info
SEAM018 Direct Process.Start usage Info

Configuration

Suppress diagnostics or exclude specific types via .editorconfig:

# Disable a rule entirely
dotnet_diagnostic.SEAM001.severity = none

# Exclude specific types from SEAM001
dotnet_code_quality.SEAM001.excluded_types = T:MyNamespace.AllowedFactory

# Exclude specific methods from SEAM004
dotnet_code_quality.SEAM004.excluded_methods = M:System.Console.WriteLine

# Exclude namespaces from SEAM009
dotnet_code_quality.SEAM009.excluded_namespaces = MyNamespace.Internal

# Set complexity threshold for SEAM011 (default: 50)
dotnet_code_quality.SEAM011.complexity_threshold = 100

Example

public class OrderService
{
    // SEAM001: Direct instantiation creates hard dependency
    private readonly EmailService _emailService = new EmailService();

    // Better: Inject the dependency
    private readonly IEmailService _emailService;

    public OrderService(IEmailService emailService)
    {
        _emailService = emailService;
    }
}

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Acknowledgments

This project is inspired by Michael Feathers' book Working Effectively with Legacy Code. The concept of "seams" as places where you can alter program behavior without editing in that place comes directly from his work. Thank you to Michael Feathers for providing such valuable insights into making legacy code testable.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.2 135 1/17/2026
2.0.1 118 1/17/2026
2.0.0 123 1/17/2026
1.0.1 124 1/16/2026
1.0.0 122 1/16/2026