Analyzer
SF0005
Flags classes with constructors above seven parameters because large parameter lists usually mean the type owns too much work.
Diagnostic contract
A class that needs a crowd of collaborators is often hiding multiple responsibilities. That raises cognitive load before the first line of behavior even runs.
A source class has an explicit instance constructor with more than seven parameters.
Constructor on {0} takes {1} parameters, exceeding the limit of 7
/analyzers/sf0005/
When it fires
These are the concrete cases to look for in code review and IDE diagnostics.
- The analyzer looks at explicit instance constructors on source classes only.
- Any constructor with more than seven parameters triggers the warning.
- The diagnostic is intentionally simple: the parameter count is a strong enough smell to start the design conversation.
Bad / better example
Use these examples to explain the rule, not just silence it.
Before
public sealed class CheckoutWorkflow(
IOrderRepository orders,
IPaymentGateway payments,
IInventoryService inventory,
INotificationService notifications,
ILogger<CheckoutWorkflow> logger,
IClock clock,
IFeatureFlags flags,
IAuditWriter audit)
{
} The constructor advertises a type that is coordinating too many concerns at once.
After
public sealed class CheckoutServices(
IOrderRepository orders,
IPaymentGateway payments,
IInventoryService inventory)
{
}
public sealed class CheckoutWorkflow(
CheckoutServices services,
INotificationService notifications,
ILogger<CheckoutWorkflow> logger)
{
} Group stable collaborators around a real responsibility instead of handing every dependency directly to the orchestration type.
Code fix
There is no automatic code fix for this rule today. Treat it as a prompt to simplify deliberately.
- Do not hide the smell behind a parameter object unless that object represents a real cohesive concept.
- If the constructor belongs to orchestration code, see whether some behavior should move into a narrower handler or service.
- Use the warning as a design review checkpoint, not as a demand to satisfy an arbitrary number.
Source and follow-up links
Use these links when you need to validate behavior against the source or connect the docs back to project tracking.
Analyzer implementation
ConstructorParameterCountAnalyzer.cs
TrackingIssue #55
Documentation tracker for the analyzer pages and related integration guidance.
FilterTwoAmTest
Large constructor surfaces make it harder to understand and change code under pressure.
Commandbudget
Use the budget view to keep the broader change-safety and cognitive-load conversation grounded.