它是最好的(我知道没有银弹,但通过使用一个可能有一些优势) - 登录调用函数,或调用它的函数?
例子:
方法1
module MongoDb =
let tryGetServer connectionString =
try
let server = new MongoClient(connectionString).GetServer()
server.Ping()
Some server
with _ -> None
Run Code Online (Sandbox Code Playgroud)
用法:
match MongoDb.tryGetServer Config.connectionString with
| None ->
logger.Information "Unable to connect to the database server."
// ... code ...
| Some srv ->
logger.Information "Successfully connected to the database server."
// ... code ...
Run Code Online (Sandbox Code Playgroud)
方法2
module MongoDb =
let tryGetServer connectionString =
try
let server = new MongoClient(connectionString).GetServer()
server.Ping()
Some server
with …Run Code Online (Sandbox Code Playgroud) f# ×1