better settings, ref #12
This commit is contained in:
parent
d95debeff9
commit
790766f753
5 changed files with 46 additions and 11 deletions
11
src/BirdsiteLive.Common/Settings/DbSettings.cs
Normal file
11
src/BirdsiteLive.Common/Settings/DbSettings.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
namespace BirdsiteLive.Common.Settings
|
||||||
|
{
|
||||||
|
public class DbSettings
|
||||||
|
{
|
||||||
|
public string Type { get; set; }
|
||||||
|
public string Host { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string User { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,5 @@
|
||||||
{
|
{
|
||||||
public string Domain { get; set; }
|
public string Domain { get; set; }
|
||||||
public string AdminEmail { get; set; }
|
public string AdminEmail { get; set; }
|
||||||
public string PostgresConnString { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
7
src/BirdsiteLive.Common/Structs/DbTypes.cs
Normal file
7
src/BirdsiteLive.Common/Structs/DbTypes.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
namespace BirdsiteLive.Common.Structs
|
||||||
|
{
|
||||||
|
public struct DbTypes
|
||||||
|
{
|
||||||
|
public static string Postgres = "postgres";
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BirdsiteLive.Common.Settings;
|
using BirdsiteLive.Common.Settings;
|
||||||
|
using BirdsiteLive.Common.Structs;
|
||||||
using BirdsiteLive.DAL.Contracts;
|
using BirdsiteLive.DAL.Contracts;
|
||||||
using BirdsiteLive.DAL.Postgres.DataAccessLayers;
|
using BirdsiteLive.DAL.Postgres.DataAccessLayers;
|
||||||
using BirdsiteLive.DAL.Postgres.Settings;
|
using BirdsiteLive.DAL.Postgres.Settings;
|
||||||
|
@ -51,15 +52,26 @@ namespace BirdsiteLive
|
||||||
var instanceSettings = Configuration.GetSection("Instance").Get<InstanceSettings>();
|
var instanceSettings = Configuration.GetSection("Instance").Get<InstanceSettings>();
|
||||||
services.For<InstanceSettings>().Use(x => instanceSettings);
|
services.For<InstanceSettings>().Use(x => instanceSettings);
|
||||||
|
|
||||||
|
var dbSettings = Configuration.GetSection("Db").Get<DbSettings>();
|
||||||
|
services.For<DbSettings>().Use(x => dbSettings);
|
||||||
|
|
||||||
|
if (string.Equals(dbSettings.Type, DbTypes.Postgres, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
var connString = $"Host={dbSettings.Host};Username={dbSettings.User};Password={dbSettings.Password};Database={dbSettings.Name}";
|
||||||
var postgresSettings = new PostgresSettings
|
var postgresSettings = new PostgresSettings
|
||||||
{
|
{
|
||||||
ConnString = instanceSettings.PostgresConnString
|
ConnString = connString
|
||||||
};
|
};
|
||||||
services.For<PostgresSettings>().Use(x => postgresSettings);
|
services.For<PostgresSettings>().Use(x => postgresSettings);
|
||||||
|
|
||||||
services.For<ITwitterUserDal>().Use<TwitterUserPostgresDal>().Singleton();
|
services.For<ITwitterUserDal>().Use<TwitterUserPostgresDal>().Singleton();
|
||||||
services.For<IFollowersDal>().Use<FollowersPostgresDal>().Singleton();
|
services.For<IFollowersDal>().Use<FollowersPostgresDal>().Singleton();
|
||||||
services.For<IDbInitializerDal>().Use<DbInitializerPostgresDal>().Singleton();
|
services.For<IDbInitializerDal>().Use<DbInitializerPostgresDal>().Singleton();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException($"{dbSettings.Type} is not supported");
|
||||||
|
}
|
||||||
|
|
||||||
services.Scan(_ =>
|
services.Scan(_ =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,8 +9,14 @@
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"Instance": {
|
"Instance": {
|
||||||
"Domain": "domain.name",
|
"Domain": "domain.name",
|
||||||
"AdminEmail": "me@domain.name",
|
"AdminEmail": "me@domain.name"
|
||||||
"PostgresConnString": "Host=127.0.0.1;Username=username;Password=password;Database=mydb"
|
},
|
||||||
|
"Db": {
|
||||||
|
"Type": "postgres",
|
||||||
|
"Host": "127.0.0.1",
|
||||||
|
"Name": "mydb",
|
||||||
|
"User": "username",
|
||||||
|
"Password": "password"
|
||||||
},
|
},
|
||||||
"Twitter": {
|
"Twitter": {
|
||||||
"ConsumerKey": "twitter.api.key",
|
"ConsumerKey": "twitter.api.key",
|
||||||
|
|
Loading…
Add table
Reference in a new issue