Argu.MicrosoftExtensions
Integrate Argu (http://fsprojects.github.io/Argu/), the F# argument and configuration parsing library, into Microsoft.Extensions hosted applications.
Install / Use
/learn @Tarmil/Argu.MicrosoftExtensionsREADME
Argu.MicrosoftExtensions
This library helps integrate Argu, the F# argument and configuration parsing library, into Microsoft.Extensions hosted applications. It provides:
- Injecting
ParseResultsinto the dependency injection; - Parsing configuration items (from eg
appSettings.json) with Argu.
Injecting ParseResults
Add Argu parse results to the dependency injection using services.AddArgu<Args>():
type Args =
| Username of string
| Password of string
type Startup() =
member this.ConfigureServices(services: IServiceCollection) =
services.AddArgu<Args>()
This method takes most of the same optional arguments as ArgumentParser.Parse():
services.AddArgu<Args>(ignoreMissing = true, raiseOnUsage = false)
Alternately, it can take a function of type IConfigurationReader -> ParseResults<Args>:
services.AddArgu<Args>(fun config ->
ArgumentParser.Create<Args>().Parse(configurationReader = config))
You can now use the injected parse results:
type MyService(args: ParseResults<Args>) =
let username = args.GetResult Username
let password = args.GetResult Password
Parsing configuration
The argument parser will also parse values from the injected configuration.
// appSettings.json
{
"username": "johndoe",
"password": "p455w0rd"
}
type Args =
| Username of string
| Password of string
To use nested keys, use CustomAppSettings with colons as separators.
// appSettings.json
{
"credentials": {
"username": "johndoe",
"password": "p455w0rd"
}
}
type Args =
| [<CustomAppSettings "credentials:username">] Username of string
| [<CustomAppSettings "credentials:password">] Password of string
To disable reading arguments from the configuration, pass useConfiguration = false to services.AddArgu().
Related Skills
node-connect
349.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.7kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
