Skip to content

Commit 21d32c0

Browse files
committed
Add Settings.cs
1 parent b87b99a commit 21d32c0

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.Extensions.Configuration;
2+
using System;
3+
4+
namespace ReferenceProject
5+
{
6+
/// <summary>
7+
/// Use this class to get an access to options
8+
/// </summary>
9+
public static class Settings
10+
{
11+
public static string GetConnectionString(string name) => Environment.ExpandEnvironmentVariables(Startup.Configuration.GetConnectionString(name));
12+
public static string Get(string name) => Environment.ExpandEnvironmentVariables(Startup.Configuration[name]);
13+
public static string TrimUrl(string url) => url.Trim(' ', '/');
14+
public static string JoinPath(this string src, string path) => $"{TrimUrl(src)}/{TrimUrl(path)}";
15+
16+
public static class Services
17+
{
18+
public static string CoolService { get; } = TrimUrl(Get("CoolServiceEndpoint")); // %ORIGIN% will be substituted with the value from an environment variable
19+
public static string AnotherService { get; } = TrimUrl(Get("AnotherServiceEndpoint"));
20+
}
21+
}
22+
}

ProjectTemplates/ReferenceProject/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Startup
2727
public Startup(IConfiguration configuration, IHostingEnvironment env, ILogger<Startup> logger)
2828
{
2929
Logger = logger;
30-
Configuration = configuration;
30+
Startup.Configuration = configuration;
3131

3232
var envPath = Path.Combine(env.ContentRootPath, ".env");
3333
if (File.Exists(envPath))
@@ -50,7 +50,7 @@ public Startup(IConfiguration configuration, IHostingEnvironment env, ILogger<St
5050
};
5151
}
5252

53-
public IConfiguration Configuration { get; }
53+
public static IConfiguration Configuration { get; private set; }
5454

5555
// This method gets called by the runtime. Use this method to add services to the container.
5656
public void ConfigureServices(IServiceCollection services)

ProjectTemplates/ReferenceProject/appsettings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@
2121
}
2222
]
2323
},
24-
"AllowedHosts": "*"
24+
"AllowedHosts": "*",
25+
"CoolServiceEndpoint": "http://%ORIGIN%/cool",
26+
"AnotherServiceEndpoint": "http://%ORIGIN%/another"
2527
}

0 commit comments

Comments
 (0)