diff --git a/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommandHandler.cs b/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommandHandler.cs index ee63b76..f8755af 100644 --- a/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommandHandler.cs +++ b/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommandHandler.cs @@ -1,4 +1,5 @@ using AipsCore.Application.Abstract.Command; +using AipsCore.Domain.Abstract; using AipsCore.Domain.Models.User.External; namespace AipsCore.Application.Models.User.Command.CreateUser; @@ -6,10 +7,12 @@ namespace AipsCore.Application.Models.User.Command.CreateUser; public class CreateUserCommandHandler : ICommandHandler { private readonly IUserRepository _userRepository; + private readonly IUnitOfWork _unitOfWork; - public CreateUserCommandHandler(IUserRepository userRepository) + public CreateUserCommandHandler(IUserRepository userRepository, IUnitOfWork unitOfWork) { _userRepository = userRepository; + _unitOfWork = unitOfWork; } public async Task Handle(CreateUserCommand command, CancellationToken cancellationToken = default) @@ -17,5 +20,6 @@ public class CreateUserCommandHandler : ICommandHandler var user = Domain.Models.User.User.Create(command.Email, command.Username); await _userRepository.Save(user, cancellationToken); + await _unitOfWork.SaveChangesAsync(cancellationToken); } } \ No newline at end of file diff --git a/dotnet/AipsCore/Domain/Abstract/IUnitOfWork.cs b/dotnet/AipsCore/Domain/Abstract/IUnitOfWork.cs new file mode 100644 index 0000000..bdfce34 --- /dev/null +++ b/dotnet/AipsCore/Domain/Abstract/IUnitOfWork.cs @@ -0,0 +1,6 @@ +namespace AipsCore.Domain.Abstract; + +public interface IUnitOfWork +{ + Task SaveChangesAsync(CancellationToken cancellationToken = default); +} \ No newline at end of file diff --git a/dotnet/AipsCore/Infrastructure/Db/EfUnitOfWork.cs b/dotnet/AipsCore/Infrastructure/Db/EfUnitOfWork.cs new file mode 100644 index 0000000..f31ed4d --- /dev/null +++ b/dotnet/AipsCore/Infrastructure/Db/EfUnitOfWork.cs @@ -0,0 +1,18 @@ +using AipsCore.Domain.Abstract; + +namespace AipsCore.Infrastructure.Db; + +public class EfUnitOfWork : IUnitOfWork +{ + private readonly AipsDbContext _dbContext; + + public EfUnitOfWork(AipsDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task SaveChangesAsync(CancellationToken cancellationToken = default) + { + await _dbContext.SaveChangesAsync(cancellationToken); + } +} \ No newline at end of file