123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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<TEntity> Of<TEntity>() where TEntity : BaseEntity;
- Task<int> SaveAsync();
- }
- public class UnitOfWork : IUnitOfWork
- {
- public readonly OracleContext ctx;
- public IRepository<TEntity> Of<TEntity>() where TEntity : BaseEntity
- {
- //UnitOfWork中的DbContext必须和Repository中的DbContext是同一个对象
- var reps = IocContainer.GetService<IRepository<TEntity>>(ctx);
- return reps;
- }
- public UnitOfWork(OracleContext ctx)
- {
- this.ctx = ctx;
- }
- public async Task<int> SaveAsync()
- {
- return await ctx.SaveChangesAsync();
- }
- public async ValueTask DisposeAsync()
- {
- await ctx.DisposeAsync();
- }
- }
- }
|