Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CleanArchitecture
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
CleanArchitecture
Commits
470e52a2
Unverified
Commit
470e52a2
authored
Nov 19, 2019
by
Eric Fleming
Committed by
GitHub
Nov 19, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #88 from ardalis/fix-domainEventDispatcher
Fixing the domain event dispatcher
parents
ad0c7d36
004fa015
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
9 deletions
+40
-9
ContainerSetup.cs
src/CleanArchitecture.Infrastructure/ContainerSetup.cs
+3
-3
DomainEventDispatcher.cs
...ture.Infrastructure/DomainEvents/DomainEventDispatcher.cs
+13
-6
DomainEventDispatcherShould.cs
...re.Tests/Core/DomainEvents/DomainEventDispatcherShould.cs
+24
-0
No files found.
src/CleanArchitecture.Infrastructure/ContainerSetup.cs
View file @
470e52a2
using
Autofac
;
using
Autofac.Extensions.DependencyInjection
;
using
CleanArchitecture.Core.
SharedKernel
;
using
CleanArchitecture.Core.
Interfaces
;
using
CleanArchitecture.Infrastructure.Data
;
using
Microsoft.Extensions.DependencyInjection
;
using
System
;
...
...
@@ -8,7 +8,7 @@ using System.Reflection;
namespace
CleanArchitecture.Infrastructure
{
public
static
class
ContainerSetup
public
static
class
ContainerSetup
{
public
static
IServiceProvider
InitializeWeb
(
Assembly
webAssembly
,
IServiceCollection
services
)
=>
new
AutofacServiceProvider
(
BaseAutofacInitialization
(
setupAction
=>
...
...
@@ -21,7 +21,7 @@ namespace CleanArchitecture.Infrastructure
{
var
builder
=
new
ContainerBuilder
();
var
coreAssembly
=
Assembly
.
GetAssembly
(
typeof
(
BaseEntit
y
));
var
coreAssembly
=
Assembly
.
GetAssembly
(
typeof
(
IRepositor
y
));
var
infrastructureAssembly
=
Assembly
.
GetAssembly
(
typeof
(
EfRepository
));
builder
.
RegisterAssemblyTypes
(
coreAssembly
,
infrastructureAssembly
).
AsImplementedInterfaces
();
...
...
src/CleanArchitecture.Infrastructure/DomainEvents/DomainEventDispatcher.cs
View file @
470e52a2
...
...
@@ -21,6 +21,16 @@ namespace CleanArchitecture.Infrastructure.DomainEvents
}
public
async
Task
Dispatch
(
BaseDomainEvent
domainEvent
)
{
var
wrappedHandlers
=
GetWrappedHandlers
(
domainEvent
);
foreach
(
DomainEventHandler
handler
in
wrappedHandlers
)
{
await
handler
.
Handle
(
domainEvent
).
ConfigureAwait
(
false
);
}
}
public
IEnumerable
<
DomainEventHandler
>
GetWrappedHandlers
(
BaseDomainEvent
domainEvent
)
{
Type
handlerType
=
typeof
(
IHandle
<>).
MakeGenericType
(
domainEvent
.
GetType
());
Type
wrapperType
=
typeof
(
DomainEventHandler
<>).
MakeGenericType
(
domainEvent
.
GetType
());
...
...
@@ -28,18 +38,15 @@ namespace CleanArchitecture.Infrastructure.DomainEvents
IEnumerable
<
DomainEventHandler
>
wrappedHandlers
=
handlers
.
Cast
<
object
>()
.
Select
(
handler
=>
(
DomainEventHandler
)
Activator
.
CreateInstance
(
wrapperType
,
handler
));
foreach
(
DomainEventHandler
handler
in
wrappedHandlers
)
{
await
handler
.
Handle
(
domainEvent
).
ConfigureAwait
(
false
);
}
return
wrappedHandlers
;
}
p
rivate
abstract
class
DomainEventHandler
p
ublic
abstract
class
DomainEventHandler
{
public
abstract
Task
Handle
(
BaseDomainEvent
domainEvent
);
}
p
rivate
class
DomainEventHandler
<
T
>
:
DomainEventHandler
p
ublic
class
DomainEventHandler
<
T
>
:
DomainEventHandler
where
T
:
BaseDomainEvent
{
private
readonly
IHandle
<
T
>
_handler
;
...
...
tests/CleanArchitecture.Tests/Core/DomainEvents/DomainEventDispatcherShould.cs
0 → 100644
View file @
470e52a2
using
CleanArchitecture.Core.Entities
;
using
CleanArchitecture.Core.Events
;
using
CleanArchitecture.Infrastructure
;
using
CleanArchitecture.Infrastructure.DomainEvents
;
using
Xunit
;
namespace
CleanArchitecture.UnitTests.Core.DomainEvents
{
public
class
DomainEventDispatcherShould
{
[
Fact
]
public
void
NotReturnAnEmptyListOfAvailableHandlers
()
{
var
container
=
ContainerSetup
.
BaseAutofacInitialization
();
var
domainEventDispatcher
=
new
DomainEventDispatcher
(
container
);
var
toDoItemCompletedEvent
=
new
ToDoItemCompletedEvent
(
new
ToDoItem
());
var
handlersForEvent
=
domainEventDispatcher
.
GetWrappedHandlers
(
toDoItemCompletedEvent
);
Assert
.
NotEmpty
(
handlersForEvent
);
}
}
}
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