{"id":13629175,"url":"https://github.com/jasonswearingen/NotNot.AppSettings","last_synced_at":"2025-04-17T04:33:07.332Z","repository":{"id":212404814,"uuid":"730961154","full_name":"jasonswearingen/NotNot.AppSettings","owner":"jasonswearingen","description":"Automatically create strongly typed C# settings objects from AppSettings.json.  Uses Source Generators. Includes a simple deserialization helper for when you are using Dependency Injection, or not.","archived":true,"fork":false,"pushed_at":"2025-01-30T02:01:57.000Z","size":593,"stargazers_count":31,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T03:43:55.821Z","etag":null,"topics":["appsettings-json","csharp","csharp-sourcegenerator","dotnet","nuget-package","source-generator"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jasonswearingen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"jasonswearingen","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-12-13T03:50:58.000Z","updated_at":"2025-03-01T18:54:34.000Z","dependencies_parsed_at":"2023-12-14T20:56:55.982Z","dependency_job_id":"b63497eb-eea5-4fa4-bdd1-c54d013126a4","html_url":"https://github.com/jasonswearingen/NotNot.AppSettings","commit_stats":null,"previous_names":["notnottech/notnot.appsettings","jasonswearingen/notnot.appsettings"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonswearingen%2FNotNot.AppSettings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonswearingen%2FNotNot.AppSettings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonswearingen%2FNotNot.AppSettings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonswearingen%2FNotNot.AppSettings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasonswearingen","download_url":"https://codeload.github.com/jasonswearingen/NotNot.AppSettings/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249270692,"owners_count":21241398,"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":["appsettings-json","csharp","csharp-sourcegenerator","dotnet","nuget-package","source-generator"],"created_at":"2024-08-01T22:01:03.816Z","updated_at":"2025-04-17T04:33:07.324Z","avatar_url":"https://github.com/jasonswearingen.png","language":"C#","funding_links":["https://github.com/sponsors/jasonswearingen"],"categories":["Content","Source Generators"],"sub_categories":["104. [NotNotAppSettings](https://ignatandrei.github.io/RSCG_Examples/v2/docs/NotNotAppSettings) , in the [FilesToCode](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#filestocode) category","Statically typed resources / configurations"],"readme":"# IMPORTANT: THIS PROJECT IS MOVING TO https://github.com/NotNotTech/NotNot-MonoRepo/tree/master/src/nuget/NotNot.AppSettings\n- why: I'm moving my public code to a single MonoRepo, to improve the maintainability and make it easier to publish more packages.\n- when: 2025-01-29.   I'll archive this repo in a few days.\n\n\n\n\n# NotNot.AppSettings\n\nAutomatically create strongly typed C# settings objects from AppSettings.json. Uses Source Generators.\n\nIncludes a simple deserialization helper for when you are using Dependency Injection, or not.\n\n## Getting Started\n\n1) Add an `appsettings.json` file to your project *(make sure it's copied to the output)*.\n2) **[Install this nuget package `NotNot.AppSettings`](https://www.nuget.org/packages/NotNot.AppSettings)**.\n3) Build your project\n4) Use the generated `AppSettings` class in your code. (See the example section below).\n\n## How it works\n\nDuring your project's build process, NotNot.AppSettings will parse the  `appsettings*.json` in your project's root folder.  These files are all merged into a single schema. Using source-generators it then creates a set of csharp classes that matches each node in the json hierarchy.\n\nAfter building your project, an `AppSettings` class contains the strongly-typed definitions,\nand an `AppSettingsBinder` helper/loader util will be found under the `{YourProjectRootNamespace}.AppSettingsGen` namespace.\n\n## Example\n\n`appsettings.json`\n\n```json\n{\n  \"Hello\": {\n\t\"World\": \"Hello back at you!\"\n  }\n}\n```\n\n`Program.cs`\n\n```csharp\nusing ExampleApp.AppSettingsGen;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Hosting;\n\nnamespace ExampleApp;\npublic class Program\n{ \n   public static async Task Main(string[] args)\n   {\n      {\n         Console.WriteLine(\"NON-DI EXAMPLE\");\n                  \n         var appSettings = ExampleApp.AppSettingsGen.AppSettingsBinder.LoadDirect();\n         Console.WriteLine(appSettings.Hello.World);         \n      }\n      {\n         Console.WriteLine(\"DI EXAMPLE\");\n\n         HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);\n         builder.Services.AddSingleton\u003cIAppSettingsBinder, AppSettingsBinder\u003e();\n         var app = builder.Build();\n         var appSettings = app.Services.GetRequiredService\u003cIAppSettingsBinder\u003e().AppSettings;\n         Console.WriteLine(appSettings.Hello.World);\n      }\n   }\n}\n```\n*See the **`./NotNot.AppSettings.Example`** folder in the repository for a fully buildable version of this example.*\n\n## Troubleshooting / Tips\n\n### How to extend the generated `AppSettings` class?\n\nYou can extend any/all of the generated code by creating a partial class in the same namespace.\n\n### Some settings not being loaded (value is `NULL`). Or:  My `appSettings.Development.json` file is not loaded\n\nEnsure the proper environment variable is set.   For example, The `appSettings.Development.json` file is only loaded when the `ASPNETCORE_ENVIRONMENT` \nor `DOTNET_ENVIORNMENT` environment variable is set to `Development`.\n\n### Intellisense not working for `AppSettings` class\n\nA strongly-typed `AppSettings` (and sub-classes) is recreated every time you build your project.\nThis may confuse your IDE and you might need to restart it to get intellisense working again.\n\n### Why are some of my nodes typed as `object`?\n\nUnder some circumstances, the type of a node's value in `appsettings.json` would be ambiguous, so `object` is used:\n\n- If the value is `null` or `undefined`\n- If the value is a POJO/Array/primitive in one appsettings file, and a different one of those three in another.\n\n\n### Tip: Backup generated code in your git repository\n\nAdd this to your `.csproj` to have the code output to `./Generated` and have it be ***ignored*** by your project.\nThis way you can check it into source control and have a backup of the generated code in case you need to stop using this package.\n```xml\n\u003c!--output the source generator build files--\u003e\n\u003cTarget Name=\"DeleteFolder\" BeforeTargets=\"PreBuildEvent\"\u003e\n\t\u003cRemoveDir Directories=\"$(CompilerGeneratedFilesOutputPath)\" /\u003e\n\u003c/Target\u003e\t\n\u003cPropertyGroup\u003e\n\t\u003cEmitCompilerGeneratedFiles\u003etrue\u003c/EmitCompilerGeneratedFiles\u003e\n\t\u003cCompilerGeneratedFilesOutputPath\u003eGenerated\u003c/CompilerGeneratedFilesOutputPath\u003e\n\u003c/PropertyGroup\u003e\n\u003cItemGroup\u003e\n\t\u003c!--Exclude the output of source generators from the compilation--\u003e\n\t\u003cCompile Remove=\"$(CompilerGeneratedFilesOutputPath)/**\" /\u003e\n\u003c/ItemGroup\u003e\n```\n\n## Contribute\n\n- If you find value from this project, consider sponsoring.\n\n### Local Development (Reference `.csproj`, not Nuget)\n\n- Add ` OutputItemType=\"Analyzer\" ReferenceOutputAssembly=\"false\"` to the `\u003cProjectReference/\u003e`\n\n### Nuget\n\n- current version is set via GitVersion.yml\n- `main` branch to create prerelease packages\n- `release` branch to create release packages\n\n\n## Acknowledgments\n\n- This project was inspired by https://github.com/FrodeHus/AppSettingsSourceGenerator which unfortunately did not match my needs in fundamental ways.\n\n## License: MPL-2.0\n\nA summary from [TldrLegal](https://www.tldrlegal.com/license/mozilla-public-license-2-0-mpl-2):\n\n\u003e   MPL is a copyleft license that is easy to comply with. You must make the source code for any of your changes available under MPL, but you can combine the MPL software with proprietary code, as long as you keep the MPL code in separate files. Version 2.0 is, by default, compatible with LGPL and GPL version 2 or greater. You can distribute binaries under a proprietary license, as long as you make the source available under MPL.\n\n**In brief**: You can basically use this project however you want, but all changes to it must be open sourced.\n\n## Changes\n\n- **`1.1.1`** : make the nuget package `\u003cPrivateAsset\u003e` so only the project that directly references it uses it. \n  - (needed for example: test projects)\n- **`1.0.0`** : polish and readme tweaks.  **Put a fork in it, it's done!**\n- **`0.12.0`** : change appsettings read logic to use \"AdditionalFiles\" workflow instead of File.IO\n- **`0.10.0`** : Initial Release.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonswearingen%2FNotNot.AppSettings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasonswearingen%2FNotNot.AppSettings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonswearingen%2FNotNot.AppSettings/lists"}