Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
丁松杰
/
Pole
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d6a21d40
authored
Feb 20, 2020
by
dingsongjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
grains WriteStateAsync 添加 发送 domaindvent的 操作
parent
e2141433
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
16 deletions
samples/apis/Backet.Api/Startup.cs
src/Pole.Core/Grains/PoleGrain.cs
src/Pole.Core/UnitOfWork/IUnitOfWork.cs
src/Pole.Core/UnitOfWork/UnitOfWork.cs
src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorage.cs
samples/apis/Backet.Api/Startup.cs
View file @
d6a21d40
using
System
;
using
System.Collections.Generic
;
using
System.Data.SqlClient
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Backet.Api.Grains
;
using
Backet.Api.Infrastructure
;
using
Microsoft.AspNetCore.Builder
;
...
...
@@ -39,9 +34,6 @@ namespace Backet.Api
.
Include
(
box
=>
box
.
BacketItems
));
options
.
IsRelatedData
=
true
;
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
...
...
src/Pole.Core/Grains/PoleGrain.cs
View file @
d6a21d40
using
Orleans
;
using
Pole.Core.Domain
;
using
Pole.Core.EventBus.Event
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
...
...
src/Pole.Core/UnitOfWork/IUnitOfWork.cs
View file @
d6a21d40
...
...
@@ -14,6 +14,6 @@ namespace Pole.Core.UnitOfWork
{
Task
CompeleteAsync
(
CancellationToken
cancellationToken
=
default
);
Task
Rollback
(
CancellationToken
cancellationToken
=
default
);
IUnitOfWork
Enlist
(
IDbTransaction
dbTransaction
,
IBus
bus
);
IUnitOfWork
Enlist
(
IDbTransaction
Adapter
dbTransactionAdapter
,
IBus
bus
);
}
}
src/Pole.Core/UnitOfWork/UnitOfWork.cs
View file @
d6a21d40
...
...
@@ -57,10 +57,9 @@ namespace Pole.Core.UnitOfWork
bus
=
null
;
}
public
IUnitOfWork
Enlist
(
IDbTransaction
dbTransaction
,
IBus
bus
)
public
IUnitOfWork
Enlist
(
IDbTransaction
Adapter
dbTransactionAdapter
,
IBus
bus
)
{
bus
.
Transaction
=
bus
.
ServiceProvider
.
GetService
<
IDbTransactionAdapter
>();
bus
.
Transaction
.
DbTransaction
=
dbTransaction
;
bus
.
Transaction
=
dbTransactionAdapter
;
this
.
bus
=
bus
;
return
this
;
}
...
...
src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorage.cs
View file @
d6a21d40
...
...
@@ -8,7 +8,10 @@ using Orleans;
using
Orleans.Runtime
;
using
Orleans.Storage
;
using
Pole.Core.Domain
;
using
Pole.Core.EventBus
;
using
Pole.Core.EventBus.Event
;
using
Pole.Core.EventBus.Transaction
;
using
Pole.Core.UnitOfWork
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
...
...
@@ -95,11 +98,36 @@ namespace Pole.Orleans.Provider.EntityframeworkCore
try
{
await
context
.
SaveChangesAsync
()
.
ConfigureAwait
(
false
);
if
(
entity
.
DomainEvents
.
Count
!=
0
)
{
using
(
var
unitOfWork
=
scope
.
ServiceProvider
.
GetRequiredService
<
IUnitOfWork
>())
{
using
(
var
dbTransactionAdapter
=
scope
.
ServiceProvider
.
GetRequiredService
<
IDbTransactionAdapter
>())
{
var
bus
=
scope
.
ServiceProvider
.
GetRequiredService
<
IBus
>();
using
(
var
transaction
=
await
context
.
Database
.
BeginTransactionAsync
())
{
dbTransactionAdapter
.
DbTransaction
=
transaction
;
unitOfWork
.
Enlist
(
dbTransactionAdapter
,
bus
);
var
publishTasks
=
entity
.
DomainEvents
.
Select
(
m
=>
bus
.
Publish
(
m
));
await
Task
.
WhenAll
(
publishTasks
);
await
context
.
SaveChangesAsync
().
ConfigureAwait
(
false
);
if
(
_options
.
CheckForETag
)
grainState
.
ETag
=
_options
.
GetETagFunc
(
entity
);
await
unitOfWork
.
CompeleteAsync
();
}
}
};
}
else
{
await
context
.
SaveChangesAsync
().
ConfigureAwait
(
false
);
if
(
_options
.
CheckForETag
)
grainState
.
ETag
=
_options
.
GetETagFunc
(
entity
);
if
(
_options
.
CheckForETag
)
grainState
.
ETag
=
_options
.
GetETagFunc
(
entity
);
}
}
catch
(
DbUpdateConcurrencyException
e
)
{
...
...
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