using DW5S.Entity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DW5S.Repostory { public interface IUnitOfWork : IAsyncDisposable { IRepository Of() where TEntity : BaseEntity; Task SaveAsync(); } public class UnitOfWork : IUnitOfWork { public readonly OracleContext ctx; public IRepository Of() where TEntity : BaseEntity { //UnitOfWork中的DbContext必须和Repository中的DbContext是同一个对象 var reps = IocContainer.GetService>(ctx); return reps; } public UnitOfWork(OracleContext ctx) { this.ctx = ctx; } public async Task SaveAsync() { return await ctx.SaveChangesAsync(); } public async ValueTask DisposeAsync() { await ctx.DisposeAsync(); } } }