Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
tsai
CAP
Commits
08ac461b
Commit
08ac461b
authored
Aug 25, 2018
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add save change when transaction commit
parent
ea6506d1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
ICapPublisher.SqlServer.cs
src/DotNetCore.CAP.SqlServer/ICapPublisher.SqlServer.cs
+1
-1
ICapTransaction.SqlServer.cs
src/DotNetCore.CAP.SqlServer/ICapTransaction.SqlServer.cs
+22
-4
No files found.
src/DotNetCore.CAP.SqlServer/ICapPublisher.SqlServer.cs
View file @
08ac461b
...
@@ -14,7 +14,7 @@ using Microsoft.EntityFrameworkCore.Storage;
...
@@ -14,7 +14,7 @@ using Microsoft.EntityFrameworkCore.Storage;
namespace
DotNetCore.CAP.SqlServer
namespace
DotNetCore.CAP.SqlServer
{
{
public
class
SqlServerPublisher
:
CapPublisherBase
,
ICallbackPublisher
public
class
SqlServerPublisher
:
CapPublisherBase
,
ICallbackPublisher
,
IDisposable
{
{
private
readonly
DbContext
_dbContext
;
private
readonly
DbContext
_dbContext
;
private
readonly
SqlServerOptions
_options
;
private
readonly
SqlServerOptions
_options
;
...
...
src/DotNetCore.CAP.SqlServer/ICapTransaction.SqlServer.cs
View file @
08ac461b
...
@@ -7,20 +7,29 @@ using System.Data;
...
@@ -7,20 +7,29 @@ using System.Data;
using
System.Data.SqlClient
;
using
System.Data.SqlClient
;
using
DotNetCore.CAP.Models
;
using
DotNetCore.CAP.Models
;
using
DotNetCore.CAP.SqlServer.Diagnostics
;
using
DotNetCore.CAP.SqlServer.Diagnostics
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Storage
;
using
Microsoft.EntityFrameworkCore.Storage
;
using
Microsoft.Extensions.DependencyInjection
;
// ReSharper disable once CheckNamespace
// ReSharper disable once CheckNamespace
namespace
DotNetCore.CAP
namespace
DotNetCore.CAP
{
{
public
class
SqlServerCapTransaction
:
CapTransactionBase
public
class
SqlServerCapTransaction
:
CapTransactionBase
{
{
private
readonly
DbContext
_dbContext
;
private
readonly
DiagnosticProcessorObserver
_diagnosticProcessor
;
private
readonly
DiagnosticProcessorObserver
_diagnosticProcessor
;
public
SqlServerCapTransaction
(
IDispatcher
dispatcher
,
public
SqlServerCapTransaction
(
DiagnosticProcessorObserver
diagnosticProcessor
)
:
base
(
dispatcher
)
IDispatcher
dispatcher
,
SqlServerOptions
sqlServerOptions
,
IServiceProvider
serviceProvider
)
:
base
(
dispatcher
)
{
{
_diagnosticProcessor
=
diagnosticProcessor
;
if
(
sqlServerOptions
.
DbContextType
!=
null
)
{
_dbContext
=
serviceProvider
.
GetService
(
sqlServerOptions
.
DbContextType
)
as
DbContext
;
}
_diagnosticProcessor
=
serviceProvider
.
GetRequiredService
<
DiagnosticProcessorObserver
>();
}
}
protected
override
void
AddToSent
(
CapPublishedMessage
msg
)
protected
override
void
AddToSent
(
CapPublishedMessage
msg
)
...
@@ -59,6 +68,7 @@ namespace DotNetCore.CAP
...
@@ -59,6 +68,7 @@ namespace DotNetCore.CAP
dbTransaction
.
Commit
();
dbTransaction
.
Commit
();
break
;
break
;
case
IDbContextTransaction
dbContextTransaction
:
case
IDbContextTransaction
dbContextTransaction
:
_dbContext
?.
SaveChanges
();
dbContextTransaction
.
Commit
();
dbContextTransaction
.
Commit
();
break
;
break
;
}
}
...
@@ -79,7 +89,15 @@ namespace DotNetCore.CAP
...
@@ -79,7 +89,15 @@ namespace DotNetCore.CAP
public
override
void
Dispose
()
public
override
void
Dispose
()
{
{
switch
(
DbTransaction
)
{
case
IDbTransaction
dbTransaction
:
dbTransaction
.
Dispose
();
break
;
case
IDbContextTransaction
dbContextTransaction
:
dbContextTransaction
.
Dispose
();
break
;
}
}
}
}
}
...
...
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