Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
ProjectsStatusManagement
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hasan.bahjat
ProjectsStatusManagement
Commits
0b7ddf50
Commit
0b7ddf50
authored
Sep 01, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix unit of work
parent
8f8ad4cc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
UnitOfWork.cs
PSManagement.Infrastructure.Persistence/UoW/UnitOfWork.cs
+36
-1
IUnitOfWork.cs
PSManagement.SharedKernel/Interfaces/IUnitOfWork.cs
+3
-0
No files found.
PSManagement.Infrastructure.Persistence/UoW/UnitOfWork.cs
View file @
0b7ddf50
using
MediatR
;
using
MediatR
;
using
Microsoft.EntityFrameworkCore.Storage
;
using
PSManagement.SharedKernel.Entities
;
using
PSManagement.SharedKernel.Entities
;
using
PSManagement.SharedKernel.Events
;
using
PSManagement.SharedKernel.Events
;
using
PSManagement.SharedKernel.Interfaces
;
using
PSManagement.SharedKernel.Interfaces
;
...
@@ -17,6 +18,7 @@ namespace PSManagement.Infrastructure.Persistence.UoW
...
@@ -17,6 +18,7 @@ namespace PSManagement.Infrastructure.Persistence.UoW
private
readonly
AppDbContext
_dbContext
;
private
readonly
AppDbContext
_dbContext
;
private
readonly
IMediator
_mediator
;
private
readonly
IMediator
_mediator
;
private
IDbContextTransaction
_transaction
;
#
endregion
Dependencies
#
endregion
Dependencies
...
@@ -29,13 +31,45 @@ namespace PSManagement.Infrastructure.Persistence.UoW
...
@@ -29,13 +31,45 @@ namespace PSManagement.Infrastructure.Persistence.UoW
#
endregion
Constructor
#
endregion
Constructor
#
region
UOW
Operations
public
async
Task
SaveChangesAsync
(
CancellationToken
cancellationToken
=
default
)
public
async
Task
SaveChangesAsync
(
CancellationToken
cancellationToken
=
default
)
{
{
await
DispatchEventsAsync
();
await
DispatchEventsAsync
();
await
_dbContext
.
SaveChangesAsync
(
cancellationToken
);
await
_dbContext
.
SaveChangesAsync
(
cancellationToken
);
try
{
_transaction
?.
Commit
();
}
catch
{
await
Rollback
();
// throw;
}
finally
{
DisposeTransaction
();
}
}
public
void
BeginTransaction
()
{
_transaction
=
_dbContext
.
Database
.
BeginTransaction
();
}
}
public
async
Task
Rollback
()
{
await
_transaction
.
RollbackAsync
();
}
private
void
DisposeTransaction
()
{
if
(
_transaction
!=
null
)
{
_transaction
.
Dispose
();
_transaction
=
null
;
}
}
#
endregion
UOW
Operations
#
region
Process
Events
#
region
Process
Events
private
async
Task
DispatchEventsAsync
()
private
async
Task
DispatchEventsAsync
()
{
{
...
@@ -112,6 +146,7 @@ namespace PSManagement.Infrastructure.Persistence.UoW
...
@@ -112,6 +146,7 @@ namespace PSManagement.Infrastructure.Persistence.UoW
{
{
_dbContext
.
Dispose
();
_dbContext
.
Dispose
();
}
}
#
endregion
Clear
And
Dispose
#
endregion
Clear
And
Dispose
}
}
}
}
PSManagement.SharedKernel/Interfaces/IUnitOfWork.cs
View file @
0b7ddf50
...
@@ -10,5 +10,8 @@ namespace PSManagement.SharedKernel.Interfaces
...
@@ -10,5 +10,8 @@ namespace PSManagement.SharedKernel.Interfaces
public
interface
IUnitOfWork
public
interface
IUnitOfWork
{
{
Task
SaveChangesAsync
(
CancellationToken
cancellationToken
=
default
);
Task
SaveChangesAsync
(
CancellationToken
cancellationToken
=
default
);
void
BeginTransaction
();
Task
Rollback
();
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment