Exemplo n.º 1
0
        /// <summary>
        /// Encapsulates several repository calls with one DbContext. Any exceptions thrown inside will end up rolling back all repository transactions.
        ///
        /// To change a repository's context to use unitOfWork's localContext, make sure to call
        /// <c>rRegistrar.ConvertContextOfRepository(myRepo).ToUse(localContext);</c>
        /// </summary>
        ///
        /// <param name="repoWork">Asynchronous lambda to do the repository transactions</param>
        public async Task Run(RepoWork repoWork)
        {
            RepositoryRegistry          rRegistry    = new RepositoryRegistry();
            RepositoryRegistryRegistrar rRegistrar   = new RepositoryRegistryRegistrar(rRegistry);
            CintaUangDbContext          localContext = null;

            try
            {
                using (var scope = serviceProvider.CreateScope())
                {
                    localContext = scope.ServiceProvider.GetService <CintaUangDbContext>();
                    localContext.Database.BeginTransaction();

                    await repoWork(rRegistrar, localContext);

                    localContext.Database.CommitTransaction();
                }
            }
            catch (Exception e)
            {
                localContext.Database.RollbackTransaction();
                throw e;
            }
            finally
            {
                /**
                 * Convert All DbContexts of all repositories registered in registry
                 */
                rRegistry.GetRepositories().ForEach(unitOfWorkRepository => unitOfWorkRepository.RevertToPreviousDbContext());
            }
        }
Exemplo n.º 2
0
 public CategoryRepository(CintaUangDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 3
0
 public MenuRepository(CintaUangDbContext dbContext, DbUtil dbUtil,
                       DbContextOptions <CintaUangDbContext> options) : base(dbContext, dbUtil)
 {
     this.options = options;
 }
Exemplo n.º 4
0
 public UserRepository(CintaUangDbContext dbContext, DbUtil dbUtil) : base(dbContext, dbUtil)
 {
 }
 public CategoryDataTableRepository(CintaUangDbContext dbContext, DbUtil dbUtil) : base(dbContext, dbUtil)
 {
 }
Exemplo n.º 6
0
 public CategoryRepository(CintaUangDbContext dbContext, DbUtil dbUtil,
                           ISubCategoryRepository subCategoryRepository) : base(dbContext, dbUtil)
 {
     this.subCategoryRepository = subCategoryRepository;
 }
Exemplo n.º 7
0
 public BaseRepository(CintaUangDbContext context, DbUtil dbUtil)
 {
     Context = context;
     DbUtil  = dbUtil;
 }
Exemplo n.º 8
0
 public void RevertToPreviousDbContext()
 {
     this.Context  = PrevDbContext;
     PrevDbContext = null;
 }
Exemplo n.º 9
0
 public void UseContext(CintaUangDbContext context)
 {
     PrevDbContext = this.Context;
     this.Context  = context;
 }
Exemplo n.º 10
0
 public void ToUse(CintaUangDbContext context)
 {
     repositoryRegistry.AddRepo(repository);
     repository.UseContext(context);
 }
Exemplo n.º 11
0
 // For EntityFrameworkCore, extend from this ctor
 public BaseRepository(CintaUangDbContext context)
 {
     Context = context;
 }
 public ExpenseDatatableRepository(CintaUangDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 13
0
 public SubCategoryRepository(CintaUangDbContext dbContext, DbUtil dbUtil) : base(dbContext, dbUtil)
 {
 }