forked from CollaboratingPlatypus/PetaPoco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppSetting.cs
44 lines (36 loc) · 1.21 KB
/
AppSetting.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
43
44
#if NETCOREAPP
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Configuration;
namespace PetaPoco.Tests.Integration
{
public class AppSetting
{
public List<ConnectionStringSetting> ConnectionStrings { get; } = new List<ConnectionStringSetting>();
private static AppSetting _instance;
public static AppSetting Instance => _instance;
static AppSetting()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
var config = builder.Build();
var app = new AppSetting();
config.GetSection("App").Bind(app);
_instance = app;
}
public ConnectionStringSetting ConnectionStringFor(string name)
{
return ConnectionStrings.First(c => c.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
}
public class ConnectionStringSetting
{
public string Name { get; set; }
public string ConnectionString { get; set; }
public string ProviderName { get; set; }
}
}
}
#endif