Skip to content

Commit

Permalink
Replace EventDriven.CQRS.Abstractions with EventDriven.DDD.Abstractions.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysneed committed Jan 1, 2022
1 parent be2a13a commit f03dbea
Show file tree
Hide file tree
Showing 41 changed files with 54 additions and 538 deletions.
37 changes: 14 additions & 23 deletions EventDriven.CQRS.sln
Original file line number Diff line number Diff line change
@@ -1,53 +1,45 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31129.286
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AFFCBFA4-9D64-43AA-AC59-D4CC54BD9C72}"
ProjectSection(SolutionItems) = preProject
ReadMe.md = ReadMe.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AF357BE9-9A6E-48A3-A995-E75F2147A43F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventDriven.CQRS.Abstractions", "src\EventDriven.CQRS.Abstractions\EventDriven.CQRS.Abstractions.csproj", "{1F665C29-BF1C-45BA-8CB9-829E85C34999}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{269CD137-4093-4100-B33E-808586D335F6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "reference-architecture", "reference-architecture", "{C4FD0AF1-927A-4860-A634-7CE342807692}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventDriven.CQRS.Tests", "test\EventDriven.CQRS.Tests\EventDriven.CQRS.Tests.csproj", "{9809006C-2F6B-44A1-8AE2-BC449368D209}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventDriven.CQRS.Tests", "test\EventDriven.CQRS.Tests\EventDriven.CQRS.Tests.csproj", "{9809006C-2F6B-44A1-8AE2-BC449368D209}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomerService", "reference-architecture\CustomerService\CustomerService.csproj", "{48983715-E6DF-462F-AF3C-769C1122794F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomerService", "reference-architecture\CustomerService\CustomerService.csproj", "{48983715-E6DF-462F-AF3C-769C1122794F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrderService", "reference-architecture\OrderService\OrderService.csproj", "{16A5B2CB-8C46-4F3E-B7A1-97C47D9F66E7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrderService", "reference-architecture\OrderService\OrderService.csproj", "{16A5B2CB-8C46-4F3E-B7A1-97C47D9F66E7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "json", "json", "{B11B21E0-7B89-4285-990A-D98793310B02}"
ProjectSection(SolutionItems) = preProject
reference-architecture\json\customers.json = reference-architecture\json\customers.json
reference-architecture\json\orders.json = reference-architecture\json\orders.json
EndProjectSection
ProjectSection(SolutionItems) = preProject
reference-architecture\json\customers.json = reference-architecture\json\customers.json
reference-architecture\json\orders.json = reference-architecture\json\orders.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "reference-architecture\Common\Common.csproj", "{FC04D111-903D-49FF-84A6-8806C71E2168}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "reference-architecture\Common\Common.csproj", "{FC04D111-903D-49FF-84A6-8806C71E2168}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dapr", "dapr", "{F0E48E00-7D72-4614-9C13-90A7B015B06F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "components", "components", "{00BA9501-787E-465C-97D0-F51295D97802}"
ProjectSection(SolutionItems) = preProject
reference-architecture\dapr\components\pubsub.yaml = reference-architecture\dapr\components\pubsub.yaml
reference-architecture\dapr\components\snssqs-pubsub.yaml = reference-architecture\dapr\components\snssqs-pubsub.yaml
EndProjectSection
ProjectSection(SolutionItems) = preProject
reference-architecture\dapr\components\pubsub.yaml = reference-architecture\dapr\components\pubsub.yaml
reference-architecture\dapr\components\snssqs-pubsub.yaml = reference-architecture\dapr\components\snssqs-pubsub.yaml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1F665C29-BF1C-45BA-8CB9-829E85C34999}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F665C29-BF1C-45BA-8CB9-829E85C34999}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F665C29-BF1C-45BA-8CB9-829E85C34999}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F665C29-BF1C-45BA-8CB9-829E85C34999}.Release|Any CPU.Build.0 = Release|Any CPU
{9809006C-2F6B-44A1-8AE2-BC449368D209}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9809006C-2F6B-44A1-8AE2-BC449368D209}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9809006C-2F6B-44A1-8AE2-BC449368D209}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -69,7 +61,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{1F665C29-BF1C-45BA-8CB9-829E85C34999} = {AF357BE9-9A6E-48A3-A995-E75F2147A43F}
{9809006C-2F6B-44A1-8AE2-BC449368D209} = {269CD137-4093-4100-B33E-808586D335F6}
{48983715-E6DF-462F-AF3C-769C1122794F} = {C4FD0AF1-927A-4860-A634-7CE342807692}
{16A5B2CB-8C46-4F3E-B7A1-97C47D9F66E7} = {C4FD0AF1-927A-4860-A634-7CE342807692}
Expand Down
16 changes: 4 additions & 12 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@ An event-driven approach to Command Query Responsibility Segregation.
- [Install Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/)
- [Initialize Dapr](https://docs.dapr.io/getting-started/install-dapr-selfhost/)

## Packages
- [EventDriven.CQRS.Abstractions](https://www.nuget.org/packages/EventDriven.CQRS.Abstractions)

## Introduction

This project builds on the principles of [Domain Driven Design](https://en.wikipedia.org/wiki/Domain-driven_design) to provide a set of abstractions and reference architecture for implementing the [Command Query Responsibility Segregation](https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs) pattern, also known as as CQRS. Because entities process commands by emitting domain events, adding [event sourcing](https://microservices.io/patterns/data/event-sourcing.html) at a later time will be relatively straightforward.

The **EventDriven.CQRS.Abstractions** library contains interfaces and abstract base classes to support these concepts:
- **Entity**: A type that has an identity with behavior and state that can change over time.
- **Command**: An object that is sent to the domain for a state change which is handled by a command handler.
- **Event**: A statement of fact about what change has been made to the domain state.

The **Reference Architecture** projects demonstrate how to apply these concepts to two microservices: `CustomerService` and `OrderService`. In addition, each service has *separate controllers for read and write operations*, thus segregating command and query responsibilities, with different sets of models, or Data Transfer Objects (DTO's).
- **Query Controller**: Uses repository to retrieve entities and converts them to DTO's with AutoMapper.
- **Command Controller**: Converts DTO's to domain entities using AutoMapper. Then hands control over to a command handler for executing business logic.
Expand All @@ -38,7 +30,7 @@ The **Reference Architecture** projects demonstrate how to apply these concepts
<img width="600" src="images/event-driven-cqrs-ref-arch.png">
</p>

### Usage: Reference Architecture Projects
### Reference Architecture

1. Run Dapr Dashboard.
- Then open http://localhost:8080 to view containers after executing `dapr run` commands.
Expand Down Expand Up @@ -81,9 +73,9 @@ The **Reference Architecture** projects demonstrate how to apply these concepts
- Switch to the Debug tab and select "with Dapr" configuration.
- Set breakpoints as needed and press F5 to start debugging.

### Usage: EventDriven.CQRS.Abstractions
### Development Guide

> This section describes how to build the Customer and Order services from scratch using the **EventDriven.CQRS.Abstractions** package. For your own project substitute `Customer` and `Order` for your own aggregate entites and related classes.
> This section describes how to build the Customer and Order services from scratch using the **EventDriven.DDD.Abstractions** package. For your own project substitute `Customer` and `Order` for your own aggregate entites and related classes.
1. Add **Domain** and **CustomerAggregate** folders to the project, then add a `Customer` class that extends `Entity`.
- Add properties representing entity state.
Expand Down Expand Up @@ -129,7 +121,7 @@ The **Reference Architecture** projects demonstrate how to apply these concepts
return new CommandResult<Customer>(CommandOutcome.Accepted, entity);
}
```
- Create a **Common** class library project and add the package **EventDriven.CQRS.Abstractions**.
- Create a **Common** class library project and add the package **EventDriven.DDD.Abstractions**.
- Reference the Common project from the CustomerService project.
- Create a `CustomerAddressUpdated` record that extends `IntegrationEvent`.
```csharp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using CustomerService.Domain.CustomerAggregate.CommandHandlers;
using CustomerService.Domain.CustomerAggregate.Commands;
using CustomerService.Helpers;
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;
using Microsoft.AspNetCore.Mvc;

namespace CustomerService.Controllers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
<PackageReference Include="EventDriven.DDD.Abstractions" Version="1.0.0" />
<PackageReference Include="EventDriven.EventBus.Dapr" Version="1.1.0" />
<PackageReference Include="MongoDB.Driver" Version="2.14.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="URF.Core.Mongo" Version="3.1.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\EventDriven.CQRS.Abstractions\EventDriven.CQRS.Abstractions.csproj" />
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using CustomerService.Domain.CustomerAggregate.Commands;
using CustomerService.Domain.CustomerAggregate.Events;
using CustomerService.Repositories;
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;
using EventDriven.EventBus.Abstractions;
using Microsoft.Extensions.Logging;
using Integration = Common.Integration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;

namespace CustomerService.Domain.CustomerAggregate.Commands
{
public record CreateCustomer(Customer Customer) : Command.Create(Customer.Id);
public record CreateCustomer(Customer Customer) : Command(Customer.Id);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;

namespace CustomerService.Domain.CustomerAggregate.Commands
{
public record RemoveCustomer(Guid EntityId) : Command.Remove(EntityId);
public record RemoveCustomer(Guid EntityId) : Command(EntityId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;

namespace CustomerService.Domain.CustomerAggregate.Commands
{
public record UpdateCustomer(Customer Customer) : Command.Update(Customer.Id, Customer.ETag);
public record UpdateCustomer(Customer Customer) : Command(Customer.Id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using CustomerService.Domain.CustomerAggregate.Commands;
using CustomerService.Domain.CustomerAggregate.Events;
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.CQRS.Abstractions.Entities;
using EventDriven.CQRS.Abstractions.Events;
using EventDriven.DDD.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Entities;
using EventDriven.DDD.Abstractions.Events;

namespace CustomerService.Domain.CustomerAggregate
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EventDriven.CQRS.Abstractions.Events;
using EventDriven.DDD.Abstractions.Events;

namespace CustomerService.Domain.CustomerAggregate.Events
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using AutoMapper;
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;
using Microsoft.AspNetCore.Mvc;
using OrderService.Domain.OrderAggregate;
using OrderService.Domain.OrderAggregate.CommandHandlers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Linq;
using System.Threading.Tasks;
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;
using Microsoft.Extensions.Logging;
using OrderService.Domain.OrderAggregate.Commands;
using OrderService.Domain.OrderAggregate.Events;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;

namespace OrderService.Domain.OrderAggregate.Commands
{
public record CancelOrder(Guid EntityId, string ETag) : Command.Update(EntityId, ETag);
public record CancelOrder(Guid EntityId, string ETag) : Command(EntityId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;

namespace OrderService.Domain.OrderAggregate.Commands
{
public record CreateOrder(Order Order) : Command.Create(Order.Id);
public record CreateOrder(Order Order) : Command(Order.Id);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;

namespace OrderService.Domain.OrderAggregate.Commands
{
public record RemoveOrder(Guid EntityId) : Command.Update(EntityId);
public record RemoveOrder(Guid EntityId) : Command(EntityId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;

namespace OrderService.Domain.OrderAggregate.Commands
{
public record ShipOrder(Guid EntityId, string ETag) : Command.Update(EntityId, ETag);
public record ShipOrder(Guid EntityId, string ETag) : Command(EntityId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;

namespace OrderService.Domain.OrderAggregate.Commands
{
public record UpdateOrder(Order Order) : Command.Update(Order.Id, Order.ETag);
public record UpdateOrder(Order Order) : Command(Order.Id);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using EventDriven.CQRS.Abstractions.Events;
using EventDriven.DDD.Abstractions.Events;

namespace OrderService.Domain.OrderAggregate.Events
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EventDriven.CQRS.Abstractions.Events;
using EventDriven.DDD.Abstractions.Events;

namespace OrderService.Domain.OrderAggregate.Events
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using EventDriven.CQRS.Abstractions.Events;
using EventDriven.DDD.Abstractions.Events;

namespace OrderService.Domain.OrderAggregate.Events
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.CQRS.Abstractions.Entities;
using EventDriven.CQRS.Abstractions.Events;
using EventDriven.DDD.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Entities;
using EventDriven.DDD.Abstractions.Events;
using OrderService.Domain.OrderAggregate.Commands;
using OrderService.Domain.OrderAggregate.Events;

Expand Down Expand Up @@ -52,7 +52,7 @@ public IEnumerable<IDomainEvent> Process(CancelOrder command)
// To process command, return one or more domain events
=> new List<IDomainEvent>
{
new OrderCancelled(command.EntityId, command.EntityEtag)
new OrderCancelled(command.EntityId, command.ETag)
};

public void Apply(OrderCancelled domainEvent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EventDriven.CQRS.Abstractions.Commands;
using EventDriven.DDD.Abstractions.Commands;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

Expand Down
4 changes: 2 additions & 2 deletions reference-architecture/OrderService/OrderService.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
<PackageReference Include="EventDriven.DDD.Abstractions" Version="1.0.0" />
<PackageReference Include="EventDriven.EventBus.Dapr" Version="1.1.0" />
<PackageReference Include="MongoDB.Driver" Version="2.14.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="URF.Core.Mongo" Version="3.1.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\EventDriven.CQRS.Abstractions\EventDriven.CQRS.Abstractions.csproj" />
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>

Expand Down
Loading

0 comments on commit f03dbea

Please sign in to comment.