diff --git a/Bootstrap.Admin/appsettings.json b/Bootstrap.Admin/appsettings.json index e35f4879..1a3979c6 100644 --- a/Bootstrap.Admin/appsettings.json +++ b/Bootstrap.Admin/appsettings.json @@ -15,7 +15,6 @@ "ConnectionStrings": { "ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa" }, - "MongoDB": "BootstrapAdmin", "DB": [ { "Enabled": false @@ -28,25 +27,25 @@ } }, { - "Enabled": true, + "Enabled": false, "ProviderName": "MySql", "ConnectionStrings": { "ba": "Server=localhost;Database=BA;Uid=argozhang;Pwd=argo@163.com;SslMode=none;" } }, { - "Enabled": true, + "Enabled": false, "ProviderName": "Npgsql", "ConnectionStrings": { "ba": "Server=localhost;Database=BootstrapAdmin;User ID=argozhang;Password=argo@163.com;" } }, { - "Enabled": true, + "Enabled": false, "Widget": "Bootstrap.DataAccess.MongoDB", "ProviderName": "MongoDB", "ConnectionStrings": { - "ba": "mongodb://localhost:27017" + "ba": "mongodb://localhost:27017;Database=BootstrapAdmin" } } ], @@ -244,4 +243,4 @@ } ] } -} +} \ No newline at end of file diff --git a/Bootstrap.Client.DataAccess.MongoDB/DbManager.cs b/Bootstrap.Client.DataAccess.MongoDB/DbManager.cs index d1c95972..70d0414a 100644 --- a/Bootstrap.Client.DataAccess.MongoDB/DbManager.cs +++ b/Bootstrap.Client.DataAccess.MongoDB/DbManager.cs @@ -9,7 +9,7 @@ using MongoDB.Driver; namespace Bootstrap.Client.DataAccess.MongoDB { /// - /// + /// 数据库操作类 /// internal static class DbManager { @@ -18,9 +18,9 @@ namespace Bootstrap.Client.DataAccess.MongoDB private static readonly object _locker = new object(); /// - /// + /// /// - private static IMongoDatabase DBAccess + private static IMongoDatabase BADatabase { get { @@ -34,7 +34,8 @@ namespace Bootstrap.Client.DataAccess.MongoDB ChangeToken.OnChange(() => ConfigurationManager.AppSettings.GetReloadToken(), () => _db = null); InitClassMap(); } - InitDb(); + if (_db == null) + InitDb("ba"); } } return _db; @@ -43,65 +44,66 @@ namespace Bootstrap.Client.DataAccess.MongoDB #region Collections /// - /// + /// Dicts 集合 /// public static IMongoCollection Dicts { get { - return DBAccess.GetCollection("Dicts"); + return BADatabase.GetCollection("Dicts"); } } /// - /// + /// Users 集合 /// public static IMongoCollection Users { get { - return DBAccess.GetCollection("Users"); + return BADatabase.GetCollection("Users"); } } /// - /// + /// Roles 集合 /// public static IMongoCollection Roles { get { - return DBAccess.GetCollection("Roles"); + return BADatabase.GetCollection("Roles"); } } /// - /// + /// Groups 集合 /// public static IMongoCollection Groups { get { - return DBAccess.GetCollection("Groups"); + return BADatabase.GetCollection("Groups"); } } /// - /// + /// Menus 集合 /// public static IMongoCollection Menus { get { - return DBAccess.GetCollection("Navigations"); + return BADatabase.GetCollection("Navigations"); } } #endregion - private static void InitDb() + private static void InitDb(string name = null) { - var client = new MongoClient(Longbow.Data.DbManager.GetConnectionString("ba")); - _db = client.GetDatabase(ConfigurationManager.AppSettings["MongoDB"]); + var (connectString, databaseName) = Longbow.Data.DbManager.GetMongoDB(name); + var client = new MongoClient(connectString); + _db = client.GetDatabase(databaseName); } private static void InitClassMap() diff --git a/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj b/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj index 5d003875..612bfef5 100644 --- a/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj +++ b/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj @@ -5,7 +5,7 @@ - + diff --git a/Bootstrap.Client/appsettings.Development.json b/Bootstrap.Client/appsettings.Development.json index 9ddc6e49..9d06767e 100644 --- a/Bootstrap.Client/appsettings.Development.json +++ b/Bootstrap.Client/appsettings.Development.json @@ -36,7 +36,8 @@ "Widget": "Bootstrap.Client.DataAccess.MongoDB", "ProviderName": "MongoDB", "ConnectionStrings": { - "ba": "mongodb://localhost:27017" + "ba": "mongodb://localhost:27017;Database=BootstrapAdmin", + "client": "mongodb://localhost:27017;Database=BootstrapClient" } } ], diff --git a/Bootstrap.Client/appsettings.json b/Bootstrap.Client/appsettings.json index 4df83da3..aef8585e 100644 --- a/Bootstrap.Client/appsettings.json +++ b/Bootstrap.Client/appsettings.json @@ -29,11 +29,11 @@ } }, { - "Enabled": true, + "Enabled": false, "Widget": "Bootstrap.Client.DataAccess.MongoDB", "ProviderName": "MongoDB", "ConnectionStrings": { - "ba": "mongodb://localhost:27017" + "ba": "mongodb://localhost:27017;Database=BootstrapAdmin" } } ], @@ -96,4 +96,4 @@ } ] } -} +} \ No newline at end of file diff --git a/Bootstrap.DataAccess.MongoDB/DbManager.cs b/Bootstrap.DataAccess.MongoDB/DbManager.cs index bfb1bb8d..b529215b 100644 --- a/Bootstrap.DataAccess.MongoDB/DbManager.cs +++ b/Bootstrap.DataAccess.MongoDB/DbManager.cs @@ -9,7 +9,7 @@ using MongoDB.Driver; namespace Bootstrap.DataAccess.MongoDB { /// - /// + /// 数据库操作类 /// internal static class DbManager { @@ -18,7 +18,7 @@ namespace Bootstrap.DataAccess.MongoDB private static readonly object _locker = new object(); /// - /// + /// IMongoDatabase 实例 /// private static IMongoDatabase DBAccess { @@ -34,7 +34,8 @@ namespace Bootstrap.DataAccess.MongoDB ChangeToken.OnChange(() => ConfigurationManager.AppSettings.GetReloadToken(), () => _db = null); InitClassMap(); } - InitDb(); + if (_db == null) + InitDb(); } } return _db; @@ -43,7 +44,7 @@ namespace Bootstrap.DataAccess.MongoDB #region Collections /// - /// + /// Logs 集合 /// public static IMongoCollection Logs { @@ -54,7 +55,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// Exceptions 集合 /// public static IMongoCollection Exceptions { @@ -64,7 +65,7 @@ namespace Bootstrap.DataAccess.MongoDB } } /// - /// + /// Dicts 集合 /// public static IMongoCollection Dicts { @@ -75,7 +76,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// Users 集合 /// public static IMongoCollection Users { @@ -86,7 +87,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// Groups 集合 /// public static IMongoCollection Groups { @@ -97,7 +98,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// Roles 集合 /// public static IMongoCollection Roles { @@ -108,7 +109,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// Menus 集合 /// public static IMongoCollection Menus { @@ -119,7 +120,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// LoginUsers 集合 /// public static IMongoCollection LoginUsers { @@ -130,7 +131,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// ResetUsers 集合 /// public static IMongoCollection ResetUsers { @@ -141,7 +142,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// Traces 集合 /// public static IMongoCollection Traces { @@ -152,7 +153,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// RejectUsers 集合 /// public static IMongoCollection RejectUsers { @@ -163,7 +164,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// Messages 集合 /// public static IMongoCollection Messages { @@ -174,7 +175,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// Tasks 集合 /// public static IMongoCollection Tasks { @@ -187,8 +188,9 @@ namespace Bootstrap.DataAccess.MongoDB private static void InitDb() { - var client = new MongoClient(Longbow.Data.DbManager.GetConnectionString()); - _db = client.GetDatabase(ConfigurationManager.AppSettings["MongoDB"]); + var (connectString, databaseName) = Longbow.Data.DbManager.GetMongoDB(); + var client = new MongoClient(connectString); + _db = client.GetDatabase(databaseName); } private static void InitClassMap() diff --git a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 8919646e..e5f02365 100644 --- a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -6,7 +6,7 @@ - + diff --git a/Bootstrap.DataAccess/DbManager.cs b/Bootstrap.DataAccess/DbManager.cs index 7ba531a6..b63ea92b 100644 --- a/Bootstrap.DataAccess/DbManager.cs +++ b/Bootstrap.DataAccess/DbManager.cs @@ -7,7 +7,7 @@ namespace Bootstrap.DataAccess /// /// /// - internal static class DbManager + public static class DbManager { /// ///