This project is read-only.
1
Vote

Stop using poor man's dependency injection

description

While most of the library accepts dependencies as constructor parameters, I wrote a lot of constructor overloads that create their own objects.

This "technique" is called poor man's dependency injection, and it's actually really bad code. Code written like this is only acceptable in the top-level library (GW2NET.csproj).

When you see code like this, refactor it so that there is only 1 constructor that has parameters for every dependency.
class Foo
{
    private readonly IBar bar;

    public Foo()
        : this(new BarImplementation())
    {
    }

    public Foo(IBar bar)
    {
        this.bar = bar;
    }
}
Refactored without poor man's dependency injection:
class Foo
{
    private readonly IBar bar;

    public Foo(IBar bar)
    {
        this.bar = bar;
    }
}