-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathUnitOfWork.cs
32 lines (28 loc) · 1.01 KB
/
UnitOfWork.cs
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
using System;
using System.Threading;
using System.Threading.Tasks;
using CompanyName.MyMeetings.BuildingBlocks.Domain;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.DomainEventsDispatching;
using Microsoft.EntityFrameworkCore;
namespace CompanyName.MyMeetings.BuildingBlocks.Infrastructure
{
public class UnitOfWork : IUnitOfWork
{
private readonly DbContext _context;
private readonly IDomainEventsDispatcher _domainEventsDispatcher;
public UnitOfWork(
DbContext context,
IDomainEventsDispatcher domainEventsDispatcher)
{
this._context = context;
this._domainEventsDispatcher = domainEventsDispatcher;
}
public async Task<int> CommitAsync(
CancellationToken cancellationToken = default,
Guid? internalCommandId = null)
{
await this._domainEventsDispatcher.DispatchEventsAsync();
return await _context.SaveChangesAsync(cancellationToken);
}
}
}