修改BUG:支持配置文件数据库类型变化时,更新数据库连接

This commit is contained in:
Argo-MacBookPro 2018-10-30 15:37:09 +08:00
parent 85f90e562e
commit 2e31c31285
1 changed files with 8 additions and 3 deletions

View File

@ -28,9 +28,10 @@ namespace Bootstrap.DataAccess.MongoDB
if (!_register)
{
_register = true;
DbAdapterManager.RegisterConfigChangeCallback(InitDb);
DbAdapterManager.RegisterConfigChangeCallback("MongoDB", InitDb);
}
InitDb();
InitClassMap();
}
return _db;
}
@ -42,11 +43,15 @@ namespace Bootstrap.DataAccess.MongoDB
if (string.IsNullOrEmpty(connectString)) throw new InvalidOperationException("Please set the BA default value in configuration file.");
var seq = connectString.Split(";", StringSplitOptions.RemoveEmptyEntries);
if (seq.Length != 2) throw new InvalidOperationException("");
if (seq.Length != 2) return;
var client = new MongoClient(seq[0]);
_db = client.GetDatabase(seq[1].Split("=", StringSplitOptions.RemoveEmptyEntries).LastOrDefault());
}
BsonSerializer.RegisterSerializer(new DateTimeSerializer(DateTimeKind.Local));
private static void InitClassMap()
{
BsonSerializer.RegisterSerializer(DateTimeSerializer.LocalInstance);
if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapDict)))
{
BsonClassMap.RegisterClassMap<BootstrapDict>(md =>