What we're used to from object-oriented systems is that dependencies are injected into the classes where they're used. There are a couple of different kinds of injections, namely:
Constructor injection
Property injection
Method injection
Constructor injection is by far the most common injection type in object-oriented programming. This is, of course, in order to make the necessary dependencies mandatory and not have to check if they're set or not.
Here is what constructor injection would look like in F#:
type CustomerRepository (csvReader : ICsvReader) = member this.Load filePath = csvReader.Load filePath |> Seq.map schema |> Seq.toList
The dependency, which here is the ICsvReader, is received in the constructor of the CustomerRepository
type.
The way to test this is pretty obvious; by creating a test double for the ICsvReader, as seen before, and injecting it into the constructor:
[<Test>] let ``should parse ID as int`` () =...