Commit 9117dc93 authored by 阿星Plus's avatar 阿星Plus

mongodb setting

parent 9384d9b1
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Plus.Core.Tests.Configuration
{
......@@ -15,6 +17,40 @@ namespace Plus.Core.Tests.Configuration
_config = builder.Build();
}
public static string MySqlConnectionString => _config["ConnectionStrings:MySql"];
private static IConfigurationSection ConnectionStrings => _config.GetSection("ConnectionStrings");
public static string MySqlConnectionString => ConnectionStrings["MySql"];
public static class MongoDb
{
private static IConfigurationSection MongoDbSection => _config.GetSection("MongoDb");
public static string ConnectionMode => MongoDbSection["ConnectionMode"];
public static string DatabaseName => MongoDbSection["DatabaseName"];
public static string Username => MongoDbSection["Username"];
public static string Password => MongoDbSection["Password"];
public static IList<MongoDbServerAddress> Servers
{
get
{
var arrays = MongoDbSection.GetSection("Servers").GetChildren().Select(x => x.Value).ToArray();
IList<MongoDbServerAddress> results = new List<MongoDbServerAddress>();
foreach (var str in arrays)
{
var item = str.Replace(":", ":").Split(':');
if (item.Length == 2)
{
results.Add(new MongoDbServerAddress() { Host = item[0], Port = item[1].ToInt() });
}
}
return results;
}
}
}
}
}
\ No newline at end of file
namespace Plus.Core.Tests.Configuration
{
public class MongoDbServerAddress
{
public string Host { get; set; }
public int Port { get; set; }
}
}
\ No newline at end of file
......@@ -7,6 +7,13 @@
"AllowedHosts": "*",
"DefaultNameOrConnectionString": "",
"ConnectionStrings": {
"MySql": "Server=localhost;User Id=root;Password=123456;Database=meowv_blog"
"MySql": "Server=localhost;User Id=root;Password=123456;Database=meowv_blog",
"MongoDb": {
"Servers": [ "localhost:27019" ],
"ConnectionMode": "",
"DatabaseName": "",
"Username": "",
"Password": ""
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment