-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserService.cs
42 lines (31 loc) · 1.33 KB
/
UserService.cs
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
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.IO;
namespace CloudWorker.ServiceInterface;
public abstract class UserService<TOptions> : UserServiceBase where TOptions : class
{
protected TOptions? _options;
protected virtual string _settingsFileName { get; } = string.Empty;
protected virtual string _environmentPrefix { get; } = string.Empty;
public UserService(ILogger logger, IConfiguration hostConfig) : base(logger, hostConfig)
{
LoadConfiguration();
}
protected virtual void LoadConfiguration()
{
var builder = new ConfigurationBuilder();
if (!string.IsNullOrEmpty(_settingsFileName))
{
var configFileBase = Path.GetDirectoryName(this.GetType().Assembly.Location);
if (string.IsNullOrWhiteSpace(configFileBase))
{
configFileBase = Directory.GetCurrentDirectory();
}
_logger.LogInformation("Look up configuration file '{configFile}' in '{configFileBase}'.", _settingsFileName, configFileBase);
builder.SetBasePath(configFileBase).AddJsonFile(_settingsFileName, true);
}
builder.AddEnvironmentVariables(_environmentPrefix);
var configuration = builder.Build();
_options = configuration.Get<TOptions>();
}
}