Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samhammerag/samhammer.configuration.childs
Supports loading configuration sections by specific customer for .NET Core projects
https://github.com/samhammerag/samhammer.configuration.childs
net-core-project-lib
Last synced: 23 days ago
JSON representation
Supports loading configuration sections by specific customer for .NET Core projects
- Host: GitHub
- URL: https://github.com/samhammerag/samhammer.configuration.childs
- Owner: SamhammerAG
- Created: 2020-08-20T18:01:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-08T11:25:59.000Z (10 months ago)
- Last Synced: 2024-03-08T12:34:49.827Z (10 months ago)
- Topics: net-core-project-lib
- Language: C#
- Homepage:
- Size: 34.2 KB
- Stars: 2
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Samhammer.Configuration.Childs
## Usage
#### How to add this to your project:
- reference this package to your project: https://www.nuget.org/packages/Samhammer.Configuration.Childs/To add it to ASP.NET Core configuration simply place .EnableChildSubstitutions() last. Make sure it is always called after all other configurations are added, else it won't behave properly!
```csharp
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((ctx, builder) =>
{
// if you have any additional configuration place it before
var customer = Environment.GetEnvironmentVariable("CUSTOMER");
builder.EnableChildSubstitutions(customer);
});
```Set enviroment variable 'Customer' to control which child substitutions are loaded in the configuration.
For local development you can do set in launchsettings.json.```json
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"CUSTOMER": "customer1"
}
```#### When to use it
If you want to deploy multiple production systems (e.g. different customers) and you don´t want to add additional appsettings.json files or additional enviroment variables for all of your settings.
#### How to use it
##### Simple Example
Example where the entry ConnectionString in appsettings.json has some default value and some substitutions values for different customers.
```json
{
"ConnectionString ": "blabla&catalog=myapp",
"customer1:ConnectionString ": "blabla&catalog=myapp-customer1",
"customer2:ConnectionString ": "blabla&catalog=myapp-customer2",
}
``````csharp
var value = configuration["ConnectionString"];
```This will return 'blabla&catalog=myapp-customer1'.
##### Additional examples
```json
{
"DatabaseOptions ": {
"HostName": "host",
"CatalogName": "db",
"UserName": "user"
},
"customer1:DatabaseOptions": {
"CatalogName": "db1",
"UserName": "user1"
}
}
``````json
{
"DatabaseOptions ": {
"HostName": "host",
"CatalogName": "db",
"UserName": "user",
"customer1": {
"CatalogName": "db1",
"UserName": "user1"
}
}
}
```## Contribute
#### How to publish package
- Create a tag and let the github action do the publishing for you