DI010

Constructor Over-Injection

constructors with too many meaningful dependencies.

Default severity: Info · Code fix: No

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.

README problem example

public sealed class ReportingService
{
    public ReportingService(
        IDep1 dep1,
        IDep2 dep2,
        IDep3 dep3,
        IDep4 dep4,
        IDep5 dep5)
    {
    }
}

README better pattern

No. Design decision required.

Repo sample extraction

Examples pulled from the sample app

Open full sample file

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)
    {
    }
}