Why it matters
often signals a class with too many responsibilities.
If one backpack needs ten straps to carry, it is probably trying to hold too much at once.
DI010
constructors with too many meaningful dependencies.
Why it matters
often signals a class with too many responsibilities.
If one backpack needs ten straps to carry, it is probably trying to hold too much at once.
Install
dotnet add package DependencyInjection.Lifetime.Analyzers --version 2.2.2
README problem example
public sealed class ReportingService
{
public ReportingService(
IDep1 dep1,
IDep2 dep2,
IDep3 dep3,
IDep4 dep4,
IDep5 dep5)
{
}
}
README better pattern
Repo sample extraction
Sample app warning case
public class ConstructorOverInjectionExample
{
public ConstructorOverInjectionExample(
IService1 s1,
IService2 s2,
IService3 s3,
IService4 s4,
IService5 s5,
IService6 s6)
{
}
}
Sample app safe pattern
public class GoodConstructorExample
{
public GoodConstructorExample(IService1 s1, IService2 s2)
{
}
}
Related guides
More documentation