This workshop covers all of the three layers from what is known as a layered architecture: the domain, application and infrastructure layer.
Protecting your high quality domain model can be accomplished by applying a so-called ports & adapters or hexagonal architecture. And you'll find out how your application's design really starts to flourish when you use CQRS with Event Sourcing.
Some of the keywords for this workshop: aggregate design, domain events, application services, commands, queries and events, event sourcing, projections, eventual consistency, layered architecture, ports & adapters, hexagonal architecture.
What you'll learn from this tutorial:
* Design a clean domain model
* Model your application's use cases as application services
* Connect those well-designed layers to the world outside
5. 5 / 76
Architecture
● Application-level design
● An application’s relation with other systems
● Framework/library/vendor choices?
● Big design upfront?
8. Thin controllers, fat models
● "Only briefly visit your controller, go to your model
as fast as you can."
● In practice: we build services, lots of them, and large
ones too.
9.
10. The effects of a framework-driven
architecture
● Implicit use case scenarios
● Implicit connections to actors
● Coupling to the framework
11. Why bad?
● Scenarios are interrelated (legacy spaghetti)
● Domain logic is mixed with infrastructure logic
● Impossible to switch frameworks
12. What do we want?
● The ability to focus on domain logic without thinking
about storage, web service, web requests, etc.
● The ability to switch to a different database,
framework, message queue, filesystem, etc.
37. 37 / 76
Application services
● Also known as "command handlers"
● Command object is a DTO
● Represents a user's intention
● Contains primitive-type values
38. 38 / 76
Application services
● Translate, and orchestrate
● From primitive-type values to rich domain objects
● Manipulates an entity
● Persists it
● May dispatch events
59. 59 / 76
Advantages of using Layers,
ports & adapters
● Offers insight into the application
● Provides a useful convention for the team
● Isolates the low-level details
● Allows for alternative implementations
● Helps with testing
61. 61 / 76
Unit tests
● Testing your units of code
● One class at a time
● No IO
● No setup required
● Mocking only dependencies "you own"
62. 62 / 76
Integration tests
● Testing your adapters
● Maybe multiple classes
● Including IO
● Some setup required
● Mocking no dependencies
63. 63 / 76
Acceptance tests
● Testing your application services
● Multiple classes
● Use cases
● Infrastructure stand-ins
64. 64 / 76
System tests
● Testing your application end-to-end
● The real deal
65. 65 / 76
Testing pyramid
● Make it well-balanced
Unit
Integration
System
Acceptance
66. 66 / 76
Testing pyramid
● Make it well-balanced
Supports development
Prevents regressionSlow, brittle
Fast, stable
Proof of effectiveness
Proof of Correctness
74. 74 / 76
A well-balanced test suite
● Adapters can be easily replaced
● Test suite is fast
● Feedback is quick
● Small amount of fragile tests
● Enables continuous delivery