Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

丁松杰 / Pole

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • Pole
  • src
  • Pole.Domain.EntityframeworkCore
  • DbContextBase.cs
Find file
BlameHistoryPermalink
  • 丁松杰's avatar
    init · 1f23761b
    丁松杰 committed 5 years ago
    1f23761b
DbContextBase.cs 1.05 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
using MediatR;
using Microsoft.EntityFrameworkCore;
using Pole.Domain;
using Pole.Domain.UnitOfWork;
using Pole.EntityframeworkCore.MediatR;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Pole.EntityframeworkCore
{
    public class DbContextBase : DbContext, IUnitOfWork
    {
        private readonly IMediator _mediator;
        public DbContextBase(DbContextOptions options, IMediator mediator) : base(options)
        {
            _mediator = mediator;
        }

        public async Task<CompleteResult> CompeleteAsync(CancellationToken cancellationToken = default)
        {
            var result = CompleteResult.SuccessResult;

            var eventHnadlersResult = await _mediator.DispatchDomainEventsAsync(this);
            if (eventHnadlersResult.Status != 1)
            {
                return new CompleteResult(eventHnadlersResult);
            }
            var dbResult = await base.SaveChangesAsync(cancellationToken);

            return result;
        }
    }
}