I asked a more general question a minute ago: How to organize the use of the DI Framework in an application? , and the feedback I received was that I used the Locator Pattern Service, not the true DI, as Martin Fowler points out here: http://martinfowler.com/articles/injection.html
Actually, I read this article only the other day, but apparently I did not quite understand it.
So let's say I have the following code:
interface ICardReader { string GetInfo(); void SetDebugMode(bool value); void Initialize(string accountToken); void ShowAmount(string amount); void Close(); ICreditCardInfo GetCardInfo(); } public class MagTekIPAD: ICardReader { public ICreditCardInfo GetCardInfo() { var card = GetCardDataFromDevice();
In this example, I could add a dependency to the constructor, and I think this is the right way to fix the 'this' script.
But what if I really need to create an unknown number for the object in question (or is there any other legitimate reason why I would need to create a dependency on the fly in the class)?
source share