Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
HIAST-Clinics
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
almohanad.hafez
HIAST-Clinics
Commits
825ca353
Commit
825ca353
authored
Aug 19, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add transactions to unit of work
parent
520307e1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
3 deletions
+17
-3
Program.cs
Clinics.Backend/API/Program.cs
+2
-2
IUnitOfWork.cs
Clinics.Backend/Domain/UnitOfWork/IUnitOfWork.cs
+7
-1
UnitOfWork.cs
Clinics.Backend/Persistence/UnitOfWork/UnitOfWork.cs
+8
-0
No files found.
Clinics.Backend/API/Program.cs
View file @
825ca353
...
...
@@ -21,9 +21,9 @@ builder.Services.AddDbContext<ClinicsDbContext>(
dbContectOptionsBuilder
.
UseSqlServer
(
databaseOptions
.
ConnectionString
,
sqlServerAction
=>
{
sqlServerAction
.
EnableRetryOnFailure
(
databaseOptions
.
MaxRetryCount
);
//
sqlServerAction.EnableRetryOnFailure(databaseOptions.MaxRetryCount);
sqlServerAction
.
CommandTimeout
(
databaseOptions
.
CommandTimeout
);
//
sqlServerAction.CommandTimeout(databaseOptions.CommandTimeout);
});
// Be careful with this option, true only in development process!
...
...
Clinics.Backend/Domain/UnitOfWork/IUnitOfWork.cs
View file @
825ca353
namespace
Domain.UnitOfWork
;
using
System.Data
;
namespace
Domain.UnitOfWork
;
public
interface
IUnitOfWork
{
public
Task
SaveChangesAsync
();
public
IDbTransaction
BeginTransaction
();
// Note that type "IDbTranaction" is from System.Data
// i.e. It's not related to any database system
}
Clinics.Backend/Persistence/UnitOfWork/UnitOfWork.cs
View file @
825ca353
using
Domain.UnitOfWork
;
using
Microsoft.EntityFrameworkCore.Storage
;
using
Persistence.Context
;
using
System.Data
;
namespace
Persistence.UnitOfWork
;
...
...
@@ -12,6 +14,12 @@ public class UnitOfWork : IUnitOfWork
_context
=
context
;
}
public
IDbTransaction
BeginTransaction
()
{
var
transaction
=
_context
.
Database
.
BeginTransaction
();
return
transaction
.
GetDbTransaction
();
}
public
async
Task
SaveChangesAsync
()
{
try
...
...
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