Skip to content

Commit 7669b3b

Browse files
Added CI; Updated Readme
1 parent ff6b9ff commit 7669b3b

File tree

7 files changed

+157
-86
lines changed

7 files changed

+157
-86
lines changed

.github/workflows/build.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build and Push
2+
on:
3+
push:
4+
branches:
5+
- '*'
6+
- '*/*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-16.04
11+
steps:
12+
- uses: actions/checkout@v1
13+
- name: Setup dotnet
14+
uses: actions/setup-dotnet@v1
15+
with:
16+
dotnet-version: 3.0.100
17+
18+
- name: Build
19+
run: dotnet build
20+
21+
push:
22+
runs-on: ubuntu-16.04
23+
if: github.ref == 'refs/heads/master'
24+
steps:
25+
- uses: actions/checkout@v1
26+
- name: Setup dotnet
27+
uses: actions/setup-dotnet@v1
28+
with:
29+
dotnet-version: 3.0.100
30+
31+
- name: Semantic Release
32+
uses: codfish/semantic-release-action@master
33+
id: semantic
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Pack and Push
38+
if: steps.semantic.outputs.new-release-published == 'true'
39+
run: |
40+
dotnet pack -p:PackageVersion=$RELEASE_VERSION -o ./
41+
dotnet nuget push ./*.nupkg -k $NUGET_KEY -s https://api.nuget.org/v3/index.json
42+
env:
43+
NUGET_KEY: ${{ secrets.NUGET_KEY }}
44+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>netstandard2.0</TargetFramework>
4+
<PackageId>C9S.Configuration.Variables</PackageId>
5+
<Authors>Cosmic9Studios</Authors>
6+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
47
</PropertyGroup>
58
<ItemGroup>
69
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />

C9S.Extensions.Configuration.sln

Lines changed: 0 additions & 34 deletions
This file was deleted.

README.md

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,115 @@ Becomes
4141

4242
After running
4343

44+
Startup.cs
45+
46+
```cs
47+
public void ConfigureServices(IServiceCollection services)
48+
{
49+
...
50+
51+
Configuration.ResolveVariables();
52+
53+
...
54+
}
55+
```
56+
57+
ResolveVariables will take any variable path and resolve it. It even works across .json files. As long as the data is stored inside the ConfigurationRoot, it is resolvable
58+
59+
## Variable Identification
60+
61+
In the ResolveVariables function you can declare what a variable is (default `{{variable}}`).
62+
63+
Example:
64+
65+
Startup.cs
66+
4467
```cs
45-
IConfigurationRoot configuration = ...
46-
configuration.ResolveVariables();
68+
public void ConfigureServices(IServiceCollection services)
69+
{
70+
...
71+
72+
Configuration.ResolveVariables("${", "}");
73+
74+
...
75+
}
76+
```
77+
78+
appsettitngs.json
79+
80+
```json
81+
{
82+
"General":
83+
{
84+
"HttpListenPort": "3000",
85+
"HttpsListenPort": "3001",
86+
"WebUrl": "https://localhost:${General.HttpsListenPort}"
87+
},
88+
"Pages":
89+
{
90+
"AuthorizeAddress": "${General.WebUrl}/api/beta/authorize",
91+
"DashboardAddress": "${General.WebUrl}/dashboard"
92+
}
93+
}
94+
```
95+
96+
Now anything inside the `${variable}` is considered a variable.
97+
98+
## Nested variables (variables inside variables)
99+
100+
If the need arises you can also resolve variables within other variables
101+
102+
Example:
103+
104+
Assuming `ASPNETCORE_ENVIRONMENT = Development`
105+
106+
appsettings.json
107+
108+
```json
109+
{
110+
"App":
111+
{
112+
"Development": {
113+
"ClientId": "FooId"
114+
}
115+
},
116+
"Auth":
117+
{
118+
"ClientID": "${App.${ASPNETCORE_ENVIRONMENT}.ClientId}"
119+
}
120+
}
121+
```
122+
123+
Will become
124+
125+
```json
126+
{
127+
"App":
128+
{
129+
"Development": {
130+
"ClientId": "FooId"
131+
}
132+
},
133+
"Auth":
134+
{
135+
"ClientID": "${App.Development.ClientId}"
136+
}
137+
}
47138
```
48139

49-
ResolveVariables will take any variable path and resolve it. It even works across .json files. As long as the data is stored inside the ConfigurationRoot, it is resolvable
140+
Which will resolve to
141+
142+
```json
143+
{
144+
"App":
145+
{
146+
"Development": {
147+
"ClientId": "FooId"
148+
}
149+
},
150+
"Auth":
151+
{
152+
"ClientID": "FooId"
153+
}
154+
}
155+
```

Samples/Samples.sln

Lines changed: 0 additions & 48 deletions
This file was deleted.

Samples/VariableInVariable/VariableInVariable.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
1111
</ItemGroup>
1212
<ItemGroup>
13-
<ProjectReference Include="..\..\C9S.Extensions.Configuration\C9S.Extensions.Configuration.csproj" />
13+
<ProjectReference Include="..\..\C9S.Configuration.Variables.csproj" />
1414
</ItemGroup>
1515
<ItemGroup>
1616
<None Update="appsettings.json" CopyToOutputDirectory="Always" />

0 commit comments

Comments
 (0)