-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigProviderExampleCachedOutput.cs
More file actions
51 lines (41 loc) · 1.58 KB
/
ConfigProviderExampleCachedOutput.cs
File metadata and controls
51 lines (41 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using Core.Extensions;
using GofConsoleApp.Examples.Structural.ProxyPattern.ConfigProviderComponents;
using GofPatterns.Structural.ProxyPattern;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using static GofConsoleApp.Examples.Structural.ProxyPattern.ConfigProviderComponents.EnumConfigEnv;
namespace GofConsoleApp.Examples.Structural.ProxyPattern;
/// <summary>
/// This example uses the Cached Output approach of Proxy Pattern.
/// It loads the configuration of the respective env and it caches
/// the output for the next time.
/// </summary>
internal class ConfigProviderExampleCachedOutput : BaseExample
{
protected override bool Execute()
{
Logger.Log("config environments", new[] { Dev, Prod, Test });
// Pattern Definition
var component = new ConfigProvider(Logger);
var proxy = new ProxyCachedOutput<EnumConfigEnv, Config>(component);
ExecuteConfigLoader(proxy);
return true;
}
private void ExecuteConfigLoader(ProxyCachedOutput<EnumConfigEnv, Config> proxy)
{
while (true)
{
var input = AcceptInputEnum(Invalid, "env to load config");
if (input == Invalid)
{
Logger.Log($"Quitting program due to input: {input}.");
return;
}
// Pattern Execution
var config = proxy.Process(input);
var str = new SerializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance).Build()
.Serialize(config);
Logger.Log(str);
}
}
}