{"id":17078524,"url":"https://github.com/dazinator/dazinator.extensions.options","last_synced_at":"2026-03-16T11:35:46.954Z","repository":{"id":45667500,"uuid":"513918888","full_name":"dazinator/Dazinator.Extensions.Options","owner":"dazinator","description":"Useful extensions to Microsoft.Extensions.Options","archived":false,"fork":false,"pushed_at":"2023-02-16T17:52:33.000Z","size":39,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-04-10T14:47:14.109Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","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/dazinator.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":"2022-07-14T13:47:27.000Z","updated_at":"2024-08-30T07:56:40.000Z","dependencies_parsed_at":"2022-07-31T16:09:01.108Z","dependency_job_id":"4f6733e8-2f7b-4d74-af78-b9a90fe9bf49","html_url":"https://github.com/dazinator/Dazinator.Extensions.Options","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.0625,"last_synced_commit":"dd5ad7eae0dc6b7927bbd903a872e9b9e2be76c6"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazinator%2FDazinator.Extensions.Options","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazinator%2FDazinator.Extensions.Options/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazinator%2FDazinator.Extensions.Options/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazinator%2FDazinator.Extensions.Options/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dazinator","download_url":"https://codeload.github.com/dazinator/Dazinator.Extensions.Options/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248630867,"owners_count":21136529,"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":[],"created_at":"2024-10-14T12:22:28.931Z","updated_at":"2026-03-16T11:35:46.925Z","avatar_url":"https://github.com/dazinator.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Features\n\nProvides additional capabilities for `Microsoft.Extensions.Options`.\n\n### Configure dynamically named options\n\nAdditional `Configure` api's are provided for configuring `Microsoft.Extensions.Options` `Options` so that you can dynamically configure an options when it is first requested, rather than at the point of registration.\n\ne.g the \"out of the box\" behaviour is to register various named options like this, specifying the name at point of registration:-\n\n```cs\n services.Configure\u003cTestOptions\u003e(\"foo\", options =\u003e\n                {                   \n                    \n                });\n\n```\n\nFor many this will be good enough and you do not need this library.\n\nHowever in an advanced scenario, suppose you wish to request new names at runtime.\nIn this case you'd like to have a way to intercept and configure new named options at the point they are requested for the first time.\n\nThis library provides such a mechanism, via some additional `Configure` style methods that allow you to supply familiar constructs such as an `Action` to confiugre the options instance, or an `IConfiguration` at the point of request as opposed to registration, where the options name is provided to you as an argument. \n\n```cs\n services.ConfigureUponRequest\u003cTestOptions\u003e()\n         .From((sp, name, options) =\u003e\n                {                   \n                    // configure your options for the requested name without having to register this name in advance.\n                });\n```\n\nYou can now request whatever named options you like at runtime, and the method above will be invoked to configure these instances how you please.\n\n\n## IConfiguration example\n\nYou can also bind from `IConfiguration`:\n\n```cs\n\n   IConfiguration config = GetConfiguration();\n\n   services.ConfigureUponRequest\u003cTestOptions\u003e()\n           .From((sp, name, options) =\u003e\n                {                   \n                    // configure your options for the requested name without having to register this name in advance.\n                     return config.GetSection(name);\n                });\n```\n\n## Use Cases (Background Info)\n\nThe primary use case for dynamic configuration of options is `IHttpClientFactory` scenarios.\n`IHttpClientFactory` uses named `HttpClientFactoryOptions` behind the scenes to configure HttpClients.\n\nBy supplying different names you can kind of \"cache bust\" and force a new HttpClient to be built that will apply new configuration.\n\nThe default `IHttpClientFactory` provided by Microsoft, builds and pools handlers for a given `name`d http client, and uses the `HttpClientFactoryOptions` registered with the same name to do this.\nSo if you've configured a http client named \"foo\" and you later use that http client via the factory - it will be built according to the `HttpClientFactoryOptions` with the same name - if you want to change this confiugration, you can't.\nTherefore if you want reconfigure a named http client at runtime (for example, change it's configured `BaseAddress`, or `Handlers`), the simplest way to acheive this is to request the http client with a different name - i.e perhaps with a version identifier appended which can be incremented.\nThis forces the `IHttpClientFactory` to miss its cache, and build a new http client which can be based on the latest configuration.\n\n```cs\nservices.ConfigureUponRequest\u003cHttpClientFactoryOptions\u003e().From((sp, name, options) =\u003e\n                {\n                  // name is the httpclient name that has been requested.\n                  var httpClientName = SplitOnDashAndTakeFirstSegment(name);\n                    // todo: load latest config for httpClientName e.g \"foo\".\n                });\n\n\n// Note: the \"-v1\", \"-v2\" acts as a kind of \"cache busting\" mechanism, to ensure that IHttpClientFactory will build a new http client\n// in conjunction with the Configure method above, that ensures we can still configure the `HttpClientFactoryOptions` based on the latest settings we have for this client.\nIHttpClientFactory httpClientFactory = GetHttpClientFactory();\nvar fooClientv1 = httpClientFactory.CreateClient(\"foo-v1\");\n\n// later you update the config / settings for \"foo-v1\" so that the latest config settings are now found with the name \"foo-v2\"\nvar fooClientv2 = httpClientFactory.CreateClient(\"foo-v2\");\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdazinator%2Fdazinator.extensions.options","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdazinator%2Fdazinator.extensions.options","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdazinator%2Fdazinator.extensions.options/lists"}