Last active
August 29, 2015 13:56
-
-
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 ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
Thanks for the tips.
Just wanted to say that this dependency is coming from a C# part :
RocketCvRuntimeContext.Instance.ConfigurationManager.GetConfigurationValue(keyValue)
Is there any recommendation on how to deal with such a code ? When you have to use some pieces of the code made for different purposes ?
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
You don't need the lambda for a start: