Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • While I get your point, I'm not quite sure you should be equating dependency injection and method parameters. Method parameters may be a "dependency" of the method (in the sense that the outcome can be different based on the parameter value), but that's not really an injected dependency. Dependency injection focuses on how classes are stitched together, not which particular values are sent to a given object. If anything, dependency injection seeks to ensure that the outcome of a method doesn't change when you pass a different parameter value, i.e. it works the same for any IFoo. Commented Aug 13, 2018 at 13:31
  • 3
    @Flater, I disagree. "Dependency injection" is simply "tell, don't ask", ie the thing, whether that be a function, object or entire library is told what its dependencies are, rather than it calling at to some service to find them. So parameters to a function most definitely are an example of dependency injection. Commented Aug 13, 2018 at 17:20
  • @Flater: though you are literally correct, for the correctness of this answer it does not matter if the first approach can be called DI or not. Commented Aug 13, 2018 at 21:18
  • I think the Options Patterns is what is needed here. Some discussion points too. Commented Aug 14, 2018 at 8:34
  • The given reason is "strings are difficult to inject", but in the proposed solution, you still need to do that - just to another class. Anything you would do to get those strings into your implementation of ISomeClassOptions - e.g. factory, hardcode it, config file - you could just as well do for SomeClass. Regarding injection of strings, you're back in the very same situation, just with an extra class. I do agree with using an own type, but the reasoning here doesn't make sense to me - maybe I'm just missing something? Commented Aug 15, 2018 at 10:05