Skip to content

Commit bfe2139

Browse files
Refactoring so we enforce to have a Repository only per Aggregate
1 parent 87d41be commit bfe2139

9 files changed

Lines changed: 18 additions & 19 deletions

File tree

src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
public class CreateOrderCommandHandler
1010
: IAsyncRequestHandler<CreateOrderCommand, bool>
1111
{
12-
private readonly IBuyerRepository _buyerRepository;
13-
private readonly IOrderRepository _orderRepository;
12+
private readonly IBuyerRepository<Buyer> _buyerRepository;
13+
private readonly IOrderRepository<Order> _orderRepository;
1414

1515
// Using DI to inject infrastructure persistence Repositories
16-
public CreateOrderCommandHandler(IBuyerRepository buyerRepository, IOrderRepository orderRepository)
16+
public CreateOrderCommandHandler(IBuyerRepository<Buyer> buyerRepository, IOrderRepository<Order> orderRepository)
1717
{
1818
if (buyerRepository == null)
1919
{

src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/ApplicationModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ protected override void Load(ContainerBuilder builder)
2727
.InstancePerLifetimeScope();
2828

2929
builder.RegisterType<BuyerRepository>()
30-
.As<IBuyerRepository>()
30+
.As<IBuyerRepository<Buyer>>()
3131
.InstancePerLifetimeScope();
3232

3333
builder.RegisterType<OrderRepository>()
34-
.As<IOrderRepository>()
34+
.As<IOrderRepository<Order>>()
3535
.InstancePerLifetimeScope();
3636
}
3737
}

src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/IBuyerRepository.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
2-
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
32
using System.Threading.Tasks;
43

54
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
65
{
76
//This is just the RepositoryContracts or Interface defined at the Domain Layer
87
//as requisite for the Buyer Aggregate
9-
public interface IBuyerRepository
10-
:IAggregateRepository
8+
9+
public interface IBuyerRepository<T> : IRepository<T> where T : IAggregateRoot
1110
{
1211
Buyer Add(Buyer buyer);
1312

src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
22

33
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
4-
{
4+
{
55
//This is just the RepositoryContracts or Interface defined at the Domain Layer
66
//as requisite for the Order Aggregate
7-
public interface IOrderRepository
8-
:IAggregateRepository
7+
8+
public interface IOrderRepository<T> : IRepository<T> where T : IAggregateRoot
99
{
1010
Order Add(Order order);
1111
}

src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
88
{
99
public class Order
10-
: Entity
10+
: Entity, IAggregateRoot
1111
{
1212
// DDD Patterns comment
1313
// Using private fields, allowed since EF Core 1.1, is a much better encapsulation

src/Services/Ordering/Ordering.Domain/SeedWork/IAggregateRepository.cs renamed to src/Services/Ordering/Ordering.Domain/SeedWork/IRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
22
{
3-
public interface IAggregateRepository
3+
public interface IRepository<T> where T : IAggregateRoot
44
{
55
IUnitOfWork UnitOfWork { get; }
66
}

src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories
99
{
1010
public class BuyerRepository
11-
: IBuyerRepository
11+
: IBuyerRepository<Buyer>
1212
{
1313
private readonly OrderingContext _context;
1414

src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories
66
{
77
public class OrderRepository
8-
: IOrderRepository
8+
: IOrderRepository<Order>
99
{
1010
private readonly OrderingContext _context;
1111

test/Services/UnitTest/Ordering/Application/NewOrderCommandHandlerTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ namespace UnitTest.Ordering.Application
1111
{
1212
public class NewOrderRequestHandlerTest
1313
{
14-
private readonly Mock<IBuyerRepository> _buyerRepositoryMock;
15-
private readonly Mock<IOrderRepository> _orderRepositoryMock;
14+
private readonly Mock<IBuyerRepository<Buyer>> _buyerRepositoryMock;
15+
private readonly Mock<IOrderRepository<Order>> _orderRepositoryMock;
1616

1717
public NewOrderRequestHandlerTest()
1818
{
1919

20-
_buyerRepositoryMock = new Mock<IBuyerRepository>();
21-
_orderRepositoryMock = new Mock<IOrderRepository>();
20+
_buyerRepositoryMock = new Mock<IBuyerRepository<Buyer>>();
21+
_orderRepositoryMock = new Mock<IOrderRepository<Order>>();
2222
}
2323

2424
[Fact]

0 commit comments

Comments
 (0)