Skip to content

Commit d186386

Browse files
author
Anthony Sneed
committed
Use EventDriven.CQRS.Abstractions v2.
1 parent 95e0c88 commit d186386

File tree

73 files changed

+696
-178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+696
-178
lines changed

ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Reference architecture for using **EventDriven** abstractions and libraries for Domain Driven Design (**DDD**), Command-Query Responsibility Segregation (**CQRS**) and Event Driven Architecture (**EDA**).
44

55
## Prerequisites
6-
- [.NET Core SDK](https://dotnet.microsoft.com/download) (5.0 or greater)
6+
- [.NET Core SDK](https://dotnet.microsoft.com/download) (6.0 or greater)
77
- [Docker Desktop](https://www.docker.com/products/docker-desktop)
88
- MongoDB Docker: `docker run --name mongo -d -p 27017:27017 -v /tmp/mongo/data:/data/db mongo`
99
- [MongoDB Client](https://robomongo.org/download):

reference-architecture/CustomerService/Controllers/CustomerCommandController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using CustomerService.Domain.CustomerAggregate;
33
using CustomerService.Domain.CustomerAggregate.Commands;
44
using CustomerService.Helpers;
5-
using EventDriven.DDD.Abstractions.Commands;
5+
using EventDriven.CQRS.Abstractions.Commands;
66
using Microsoft.AspNetCore.Mvc;
77

88
namespace CustomerService.Controllers

reference-architecture/CustomerService/Controllers/CustomerQueryController.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using AutoMapper;
2+
using CustomerService.Domain.CustomerAggregate.Queries;
23
using CustomerService.DTO.Read;
3-
using CustomerService.Repositories;
4+
using EventDriven.CQRS.Abstractions.Queries;
45
using Microsoft.AspNetCore.Mvc;
56

67
namespace CustomerService.Controllers
@@ -9,30 +10,32 @@ namespace CustomerService.Controllers
910
[ApiController]
1011
public class CustomerQueryController : ControllerBase
1112
{
12-
private readonly ICustomerRepository _repository;
13+
private readonly IQueryBroker _queryBroker;
1314
private readonly IMapper _mapper;
1415

15-
public CustomerQueryController(ICustomerRepository repository, IMapper mapper)
16+
public CustomerQueryController(
17+
IQueryBroker queryBroker,
18+
IMapper mapper)
1619
{
17-
_repository = repository;
20+
_queryBroker = queryBroker;
1821
_mapper = mapper;
1922
}
2023

2124
// GET api/customer
2225
[HttpGet]
2326
public async Task<IActionResult> GetCustomers()
2427
{
25-
var customers = await _repository.GetAsync();
28+
var customers = await _queryBroker.SendAsync(new GetCustomers());
2629
var result = _mapper.Map<IEnumerable<CustomerView>>(customers);
2730
return Ok(result);
2831
}
2932

3033
// GET api/customer/id
3134
[HttpGet]
32-
[Route("{id}")]
35+
[Route("{id:guid}")]
3336
public async Task<IActionResult> GetCustomer([FromRoute] Guid id)
3437
{
35-
var customer = await _repository.GetAsync(id);
38+
var customer = await _queryBroker.SendAsync(new GetCustomer(id));
3639
if (customer == null) return NotFound();
3740
var result = _mapper.Map<CustomerView>(customer);
3841
return Ok(result);

reference-architecture/CustomerService/CustomerService.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
11-
<PackageReference Include="EventDriven.DDD.Abstractions" Version="2.0.0-beta1" />
11+
<PackageReference Include="EventDriven.CQRS.Abstractions" Version="2.0.0-beta3" />
1212
<PackageReference Include="EventDriven.DependencyInjection.URF.Mongo" Version="1.1.0" />
1313
<PackageReference Include="EventDriven.EventBus.Dapr" Version="1.2.0" />
1414
<PackageReference Include="EventDriven.EventBus.Dapr.EventCache.Mongo" Version="1.2.0" />

reference-architecture/CustomerService/DTO/Read/CustomerView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class CustomerView
1010
public string State { get; set; } = null!;
1111
public string Country { get; set; } = null!;
1212
public string PostalCode { get; set; } = null!;
13-
public string ETag { get; set; } = null!;
13+
public string? ETag { get; set; }
1414
}
1515
}

reference-architecture/CustomerService/Domain/CustomerAggregate/Handlers/CreateCustomerHandler.cs renamed to reference-architecture/CustomerService/Domain/CustomerAggregate/CommandHandlers/CreateCustomerHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using CustomerService.Domain.CustomerAggregate.Commands;
22
using CustomerService.Repositories;
3-
using EventDriven.DDD.Abstractions.Commands;
3+
using EventDriven.CQRS.Abstractions.Commands;
44

5-
namespace CustomerService.Domain.CustomerAggregate.Handlers;
5+
namespace CustomerService.Domain.CustomerAggregate.CommandHandlers;
66

77
public class CreateCustomerHandler : ICommandHandler<Customer, CreateCustomer>
88
{
@@ -21,11 +21,12 @@ public async Task<CommandResult<Customer>> Handle(CreateCustomer command, Cancel
2121
{
2222
// Process command
2323
_logger.LogInformation("Handling command: {CommandName}", nameof(CreateCustomer));
24+
if (command.Entity == null) return new CommandResult<Customer>(CommandOutcome.InvalidCommand);
2425
var domainEvent = command.Entity.Process(command);
2526

2627
// Apply events
2728
command.Entity.Apply(domainEvent);
28-
29+
2930
// Persist entity
3031
var entity = await _repository.AddAsync(command.Entity);
3132
if (entity == null) return new CommandResult<Customer>(CommandOutcome.InvalidCommand);

reference-architecture/CustomerService/Domain/CustomerAggregate/Handlers/RemoveCustomerHandler.cs renamed to reference-architecture/CustomerService/Domain/CustomerAggregate/CommandHandlers/RemoveCustomerHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using CustomerService.Domain.CustomerAggregate.Commands;
22
using CustomerService.Repositories;
3-
using EventDriven.DDD.Abstractions.Commands;
3+
using EventDriven.CQRS.Abstractions.Commands;
44

5-
namespace CustomerService.Domain.CustomerAggregate.Handlers;
5+
namespace CustomerService.Domain.CustomerAggregate.CommandHandlers;
66

77
public class RemoveCustomerHandler : ICommandHandler<RemoveCustomer>
88
{

reference-architecture/CustomerService/Domain/CustomerAggregate/Handlers/UpdateCustomerHandler.cs renamed to reference-architecture/CustomerService/Domain/CustomerAggregate/CommandHandlers/UpdateCustomerHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
using Common.Integration.Events;
33
using CustomerService.Domain.CustomerAggregate.Commands;
44
using CustomerService.Repositories;
5-
using EventDriven.DDD.Abstractions.Commands;
5+
using EventDriven.CQRS.Abstractions.Commands;
66
using EventDriven.DDD.Abstractions.Repositories;
77
using EventDriven.EventBus.Abstractions;
88
using Integration = Common.Integration;
99

10-
namespace CustomerService.Domain.CustomerAggregate.Handlers;
10+
namespace CustomerService.Domain.CustomerAggregate.CommandHandlers;
1111

1212
public class UpdateCustomerHandler : ICommandHandler<Customer, UpdateCustomer>
1313
{
@@ -32,6 +32,7 @@ public async Task<CommandResult<Customer>> Handle(UpdateCustomer command, Cancel
3232
{
3333
// Process command
3434
_logger.LogInformation("Handling command: {CommandName}", nameof(UpdateCustomer));
35+
if (command.Entity == null) return new CommandResult<Customer>(CommandOutcome.InvalidCommand);
3536
var domainEvent = command.Entity.Process(command);
3637

3738
// Apply events
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using EventDriven.DDD.Abstractions.Commands;
1+
using EventDriven.CQRS.Abstractions.Commands;
22

33
namespace CustomerService.Domain.CustomerAggregate.Commands
44
{
5-
public record CreateCustomer(Customer Entity) : Command<Customer>(Entity);
5+
public record CreateCustomer(Customer? Entity) : Command<Customer>(Entity);
66
}

reference-architecture/CustomerService/Domain/CustomerAggregate/Commands/RemoveCustomer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using EventDriven.DDD.Abstractions.Commands;
1+
using EventDriven.CQRS.Abstractions.Commands;
22

33
namespace CustomerService.Domain.CustomerAggregate.Commands
44
{

0 commit comments

Comments
 (0)