using JiShe.CollectBus.Common.Extensions.DependencyInjections; using MongoDB.Driver; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JiShe.CollectBus.MongoDB { public class UnitOfWork : IUnitOfWork { private readonly IMongoContext _context; public UnitOfWork(IMongoContext context) { _context = context; } /// /// 提交保存更改 /// /// MongoDB 会话(session)对象 /// public async Task Commit(IClientSessionHandle session) { return await _context.SaveChangesAsync(session) > 0; } /// /// 初始化MongoDB会话对象session /// /// public async Task InitTransaction() { return await _context.StartSessionAsync(); } public void Dispose() { _context.Dispose(); } } }