{"id":16367860,"url":"https://github.com/colinbull/strongnetcoreconfig","last_synced_at":"2025-10-26T07:30:42.900Z","repository":{"id":139933690,"uuid":"114991909","full_name":"colinbull/StrongNetCoreConfig","owner":"colinbull","description":"True strongly type Net core configuration access","archived":false,"fork":false,"pushed_at":"2017-12-21T22:11:53.000Z","size":62,"stargazers_count":6,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-31T16:46:27.025Z","etag":null,"topics":["fsharp","netcore2"],"latest_commit_sha":null,"homepage":null,"language":"F#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/colinbull.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-12-21T10:09:03.000Z","updated_at":"2019-07-01T05:51:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"dc4df548-84ca-4f4f-9b44-32c1ebe33fc2","html_url":"https://github.com/colinbull/StrongNetCoreConfig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinbull%2FStrongNetCoreConfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinbull%2FStrongNetCoreConfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinbull%2FStrongNetCoreConfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinbull%2FStrongNetCoreConfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/colinbull","download_url":"https://codeload.github.com/colinbull/StrongNetCoreConfig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238284742,"owners_count":19446720,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fsharp","netcore2"],"created_at":"2024-10-11T02:51:02.405Z","updated_at":"2025-10-26T07:30:37.605Z","avatar_url":"https://github.com/colinbull.png","language":"F#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Strongly type access for .NET Core for F#\n\nTrue strongly type Net core configuration access. This simple library, provides a hook to use F# Type provides with .net core configuration system.\n\n**Note** this project doesn't actually add anything that wasn't already there in the F# + netcore ecosystem. It just ties together a few concepts. \n\nCurrently, no NuGet pacakage is available, but the actual extension is only a single file which can be referenced using [Paket](https://github.com/fsprojects/Paket), \n\n    github colinbull/StrongNetCoreConfig src/StrongConfigurationExtensions.fs\n\nFirstly, create the type providers based on configuration samples, \n```fsharp\ntype CommonConfiguration = JsonProvider\u003c\"appsettings.json\"\u003e\ntype EnvironmentConfiguration = JsonProvider\u003c\"appsettings.production.json\"\u003e\n\ntype CommonConfigRoot = CommonConfiguration.Root\ntype EnvConfigRoot = EnvironmentConfiguration.Root\n```\nOptionally then we can define a wrapper object for this provided configuration. \n```fsharp\ntype Configuration = \n    { Common : CommonConfigRoot\n    Environment : EnvConfigRoot }\n    static member Empty = \n        {\n            Common = CommonConfiguration.GetSample()\n            Environment = EnvironmentConfiguration.GetSample()\n        }\n    member x.Refresh(?common:CommonConfigRoot, ?env:EnvConfigRoot) = \n        {\n        Common = defaultArg common x.Common\n        Environment = defaultArg env x.Environment\n        }\n\n    static member OnChange (configRef:Configuration ref) (env:IHostingEnvironment) path  = \n        let envPath = sprintf \"appsettings.%s.json\" env.EnvironmentName \n        match Path.GetFileName(path) with \n        | \"appsettings.json\" -\u003e \n            printfn \"Updating Common config\"\n            configRef := ((!configRef).Refresh(common = CommonConfiguration.Load(path)))\n        | a when a = envPath -\u003e \n            printfn \"Updating Environment config\"\n            configRef := ((!configRef).Refresh(env = EnvironmentConfiguration.Load(path)))\n        | _ -\u003e ()\n```\nAlso then we need to setup a global instance of our configuration. \n```fsharp\nlet configInstance = ref Configuration.Empty\n```\n\nWe can register to listen for changes in the configuration, this is done as part of the ConfigureService call on the WebHostBuilder \n```fsharp\nlet configureServices (services : IServiceCollection) =\n    let sp  = services.BuildServiceProvider()\n    let env = sp.GetService\u003cIHostingEnvironment\u003e()\n\n    //-------------------  Setup typed configuration\n    let config = sp.GetService\u003cIConfiguration\u003e() \n    config.RegisterConfigChange(Configuration.OnChange configInstance,env)\n```\nAlso at this point we can choose to transiently inject our global config instance to make it available to out Http handlers. \n```fsharp\nservices.AddTransient\u003cConfiguration\u003e(fun _ -\u003e !configInstance) |\u003e ignore\n```\nAs a nice touch, if you are using giraffe, you can add the following handler to resolve the configuration for you, for example, \n```fsharp\nlet withConfig\u003c'a\u003e (f : 'a -\u003e HttpHandler) : HttpHandler = \n    (fun (next:HttpFunc) (ctx:HttpContext) -\u003e \n        task { \n            let cfg = ctx.GetService\u003c'a\u003e()\n            return! (f cfg) next ctx\n        }\n    )\n```\nand then you'll have access to the config in your routes. \n```fsharp\nlet webapp = \n    choose [ \n        route \"/\" \u003e=\u003e withConfig\u003cConfiguration\u003e (fun a -\u003e \n                        razorHtmlView \"index\" { \n                                            IntValue = a.Common.Test.OptionInt; \n                                            StringValue = a.Common.Test.OptionString; \n                                            EnableCaching = a.Environment.Caching.EnableCaching\n                                        }) \n    ]\n```\nSee the [samples](samples) for more info. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolinbull%2Fstrongnetcoreconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcolinbull%2Fstrongnetcoreconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolinbull%2Fstrongnetcoreconfig/lists"}