Skip to content

Commit d7e4816

Browse files
committed
Add the implemantation to the sample
1 parent d7ee6c8 commit d7e4816

File tree

7 files changed

+61
-5
lines changed

7 files changed

+61
-5
lines changed

.vscode/launch.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"request": "launch",
1111
"preLaunchTask": "build",
1212
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceFolder}/test/CZ.Extensions.Configuration.ReferenceResolver.Tests/bin/Debug/netcoreapp3.1/CZ.Extensions.Configuration.ReferenceResolver.Tests.dll",
13+
"program": "${workspaceFolder}/samples/CZ.Extensions.Configuration.ReferenceResolver.Samples.Web/bin/Debug/netcoreapp3.1/CZ.Extensions.Configuration.ReferenceResolver.Samples.Web.dll",
1414
"args": [],
15-
"cwd": "${workspaceFolder}/test/CZ.Extensions.Configuration.ReferenceResolver.Tests",
15+
"cwd": "${workspaceFolder}/samples/CZ.Extensions.Configuration.ReferenceResolver.Samples.Web",
1616
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
1717
"console": "internalConsole",
1818
"stopAtEntry": false
@@ -24,4 +24,4 @@
2424
"processId": "${command:pickProcess}"
2525
}
2626
]
27-
}
27+
}

.vscode/tasks.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"args": [
1313
"build",
14-
"${workspaceFolder}/test/CZ.Extensions.Configuration.ReferenceResolver.Tests/CZ.Extensions.Configuration.ReferenceResolver.Tests.csproj",
14+
"${workspaceFolder}/CZ.Extensions.Configuration.ReferenceResolver.sln",
1515
"/property:GenerateFullPaths=true",
1616
"/consoleloggerparameters:NoSummary"
1717
],

CZ.Extensions.Configuration.ReferenceResolver.sln

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2DC9E32A-B
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CZ.Extensions.Configuration.ReferenceResolver.Tests", "test\CZ.Extensions.Configuration.ReferenceResolver.Tests\CZ.Extensions.Configuration.ReferenceResolver.Tests.csproj", "{89737D7C-2712-432F-A17A-A08EB8DDBC58}"
1313
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{AEC97108-3CBC-4240-B9D3-351438A4B6FE}"
15+
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CZ.Extensions.Configuration.ReferenceResolver.Samples.Web", "samples\CZ.Extensions.Configuration.ReferenceResolver.Samples.Web\CZ.Extensions.Configuration.ReferenceResolver.Samples.Web.csproj", "{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}"
17+
EndProject
1418
Global
1519
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1620
Debug|Any CPU = Debug|Any CPU
@@ -48,9 +52,22 @@ Global
4852
{89737D7C-2712-432F-A17A-A08EB8DDBC58}.Release|x64.Build.0 = Release|Any CPU
4953
{89737D7C-2712-432F-A17A-A08EB8DDBC58}.Release|x86.ActiveCfg = Release|Any CPU
5054
{89737D7C-2712-432F-A17A-A08EB8DDBC58}.Release|x86.Build.0 = Release|Any CPU
55+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
57+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Debug|x64.ActiveCfg = Debug|Any CPU
58+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Debug|x64.Build.0 = Debug|Any CPU
59+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Debug|x86.ActiveCfg = Debug|Any CPU
60+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Debug|x86.Build.0 = Debug|Any CPU
61+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
62+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Release|Any CPU.Build.0 = Release|Any CPU
63+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Release|x64.ActiveCfg = Release|Any CPU
64+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Release|x64.Build.0 = Release|Any CPU
65+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Release|x86.ActiveCfg = Release|Any CPU
66+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF}.Release|x86.Build.0 = Release|Any CPU
5167
EndGlobalSection
5268
GlobalSection(NestedProjects) = preSolution
5369
{6ACD3199-5849-47BD-9F99-85E2232F9DE6} = {3FBF03F0-C0F8-4FE6-9249-0846A35DF65D}
5470
{89737D7C-2712-432F-A17A-A08EB8DDBC58} = {2DC9E32A-B558-482A-87B6-D46B14330F87}
71+
{D80C215F-D88A-43EF-8F0E-6DF1D325D3DF} = {AEC97108-3CBC-4240-B9D3-351438A4B6FE}
5572
EndGlobalSection
5673
EndGlobal

samples/CZ.Extensions.Configuration.ReferenceResolver.Samples.Web/CZ.Extensions.Configuration.ReferenceResolver.Samples.Web.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<ProjectReference Include="..\..\src\CZ.Extensions.Configuration.ReferenceResolver\CZ.Extensions.Configuration.ReferenceResolver.csproj" />
9+
</ItemGroup>
10+
711
</Project>

samples/CZ.Extensions.Configuration.ReferenceResolver.Samples.Web/Program.cs

+19
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ public static void Main(string[] args)
1818

1919
public static IHostBuilder CreateHostBuilder(string[] args) =>
2020
Host.CreateDefaultBuilder(args)
21+
// Extend the default configuration provider
22+
.ConfigureAppConfiguration((hostingContext, config) =>
23+
{
24+
// Let's add some values as an example
25+
var dict = new Dictionary<string, string>
26+
{
27+
{"MemoryMessage", "Hello from memory!"}
28+
};
29+
30+
config.AddInMemoryCollection(dict);
31+
32+
// We have to build the current state of the configuration to use it as a source for the resolver.
33+
var buildConfig = config.Build();
34+
35+
// Add the resolver to the CobfigurationBuilder with the actual build configuration.
36+
// This will resolve all references in the actual configuration.
37+
// Configuration sources added after this will not be resolved!
38+
config.AddReferenceResolver(buildConfig);
39+
})
2140
.ConfigureWebHostDefaults(webBuilder =>
2241
{
2342
webBuilder.UseStartup<Startup>();

samples/CZ.Extensions.Configuration.ReferenceResolver.Samples.Web/Startup.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ namespace CZ.Extensions.Configuration.ReferenceResolver.Samples.Web
77
using Microsoft.AspNetCore.Builder;
88
using Microsoft.AspNetCore.Hosting;
99
using Microsoft.AspNetCore.Http;
10+
using Microsoft.Extensions.Configuration;
1011
using Microsoft.Extensions.DependencyInjection;
1112
using Microsoft.Extensions.Hosting;
1213

1314
public class Startup
1415
{
16+
public Startup(IConfiguration configuration)
17+
{
18+
Configuration = configuration;
19+
}
20+
21+
public IConfiguration Configuration { get; }
22+
1523
// This method gets called by the runtime. Use this method to add services to the container.
1624
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
1725
public void ConfigureServices(IServiceCollection services)
@@ -32,7 +40,12 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3240
{
3341
endpoints.MapGet("/", async context =>
3442
{
35-
await context.Response.WriteAsync("Hello World!");
43+
// The value from the appsettings.json:
44+
// "Reference":{
45+
// "Sample1": "{References[MemoryMessage]@Value read from the in memory provider}"
46+
// },
47+
// The reverence is resolved with the value from the memory provider
48+
await context.Response.WriteAsync(this.Configuration["Reference:Sample1"]);
3649
});
3750
});
3851
}

samples/CZ.Extensions.Configuration.ReferenceResolver.Samples.Web/appsettings.json

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"Reference":{
3+
"Sample1": "{References[MemoryMessage]@Value read from the in memory provider}"
4+
},
25
"Logging": {
36
"LogLevel": {
47
"Default": "Information",

0 commit comments

Comments
 (0)