Skip to main content
added C# header
Source Link
JimmyJames
  • 30.9k
  • 3
  • 59
  • 110

There is a kind of rule in dependency injection literature, stating that we should declare all arguments in the constructor

Where? In which literature?

Given your examples, if _input is, in fact, run-time input, why don't you just write the class like the following?

public class Transformation
{
    private readonly IConditionStrategy condition;
    
    public Transformation(IConditionStrategy condition)
    {
        this.condition = condition;
    }
    
    public ISource Transform(ISource input)
    {
        ISource source = new Source();
        foreach(var i in input)
            if(input.Check(i))
                source.Add(i);

        return source;
    }
}
public class Transformation
{
    private readonly IConditionStrategy condition;
    
    public Transformation(IConditionStrategy condition)
    {
        this.condition = condition;
    }
    
    public ISource Transform(ISource input)
    {
        ISource source = new Source();
        foreach(var i in input)
            if(input.Check(i))
                source.Add(i);

        return source;
    }
}

There is a kind of rule in dependency injection literature, stating that we should declare all arguments in the constructor

Where? In which literature?

Given your examples, if _input is, in fact, run-time input, why don't you just write the class like the following?

public class Transformation
{
    private readonly IConditionStrategy condition;
    
    public Transformation(IConditionStrategy condition)
    {
        this.condition = condition;
    }
    
    public ISource Transform(ISource input)
    {
        ISource source = new Source();
        foreach(var i in input)
            if(input.Check(i))
                source.Add(i);

        return source;
    }
}

There is a kind of rule in dependency injection literature, stating that we should declare all arguments in the constructor

Where? In which literature?

Given your examples, if _input is, in fact, run-time input, why don't you just write the class like the following?

public class Transformation
{
    private readonly IConditionStrategy condition;
    
    public Transformation(IConditionStrategy condition)
    {
        this.condition = condition;
    }
    
    public ISource Transform(ISource input)
    {
        ISource source = new Source();
        foreach(var i in input)
            if(input.Check(i))
                source.Add(i);

        return source;
    }
}
Source Link
Mark Seemann
  • 3.9k
  • 26
  • 30

There is a kind of rule in dependency injection literature, stating that we should declare all arguments in the constructor

Where? In which literature?

Given your examples, if _input is, in fact, run-time input, why don't you just write the class like the following?

public class Transformation
{
    private readonly IConditionStrategy condition;
    
    public Transformation(IConditionStrategy condition)
    {
        this.condition = condition;
    }
    
    public ISource Transform(ISource input)
    {
        ISource source = new Source();
        foreach(var i in input)
            if(input.Check(i))
                source.Add(i);

        return source;
    }
}