CI / Go Backend (push) Canceled after 0s
初始化 monorepo: Go后端(7微服务) + Unity客户端(9模块) + 启动器 HTML5原型: Three.js 3D体素世界, Perlin噪声地形, 原版材质, 22种方块 Minecraft创造模式背包: 双栏布局, 拖拽移动物品, 方向性元件引脚 AI助搭策划文档 + 客户端/服务端骨架 + Docker Compose + CI
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using LiteDB;
|
|
using PCL.Core.App.IoC;
|
|
|
|
namespace PCL.Core.App.Database;
|
|
|
|
[LifecycleService(LifecycleState.Loading)]
|
|
public class DatabaseService() : GeneralService("database", "数据库管理")
|
|
{
|
|
private static readonly ConcurrentDictionary<string, LiteDatabase> _Instances = new();
|
|
|
|
/// <inheritdoc />
|
|
public override void Stop()
|
|
{
|
|
foreach (var instance in _Instances.Values)
|
|
{
|
|
instance.Dispose();
|
|
}
|
|
|
|
_Instances.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the database connenction from specified connection path.<br/>
|
|
/// If not exists, a new connection will be created and cached.
|
|
/// </summary>
|
|
/// <returns>Getted connenction instance.</returns>
|
|
/// <exception cref="ArgumentException">Throw if connection path is invalid.</exception>
|
|
public static LiteDatabase GetConnection(string connectionPath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(connectionPath))
|
|
{
|
|
throw new ArgumentException("Connection string canot be null or whitespace.", nameof(connectionPath));
|
|
}
|
|
|
|
return _Instances.GetOrAdd(connectionPath, cp => new LiteDatabase(cp));
|
|
}
|
|
} |