Skip to content

Instantly share code, notes, and snippets.

@tjaskula
Last active August 29, 2015 13:56
Show Gist options
  • Save tjaskula/9019486 to your computer and use it in GitHub Desktop.
Save tjaskula/9019486 to your computer and use it in GitHub Desktop.
Is this considered a bad practice, using a hard dependency inside a function. Something like ServiceLocator anti pattern in OOP ?
// And here is how both of them are composed in a higher level module so I can pass in another function without hard dependency for testing
let keys = [| "SOclient_id"; "SOscope"; "SOredirect_uri"|]
let queryParameters = readConfigApi keys readConfigurationValue
// tried to isolate a hard dependency in different function
let readConfigurationValue keyValue =
(keyValue, RocketCvRuntimeContext.Instance.ConfigurationManager.GetConfigurationValue(keyValue))
// here is the high level function using indirectly the first one
let readConfigApi keys configValueReader =
keys |> Seq.map (fun e ->
e |> configValueReader
)
|> Map.ofSeq
@7sharp9
Copy link

7sharp9 commented Feb 17, 2014

You could add a function that had the same signature to the readConfigurationValue function and pass in the RocketCvRuntimeContext.Instance.ConfigurationManager.GetConfigurationValue function in. Then you could abstract to another configuration provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment