Browse Source

Refactoring so we enforce to have a Repository only per Aggregate

pull/68/head
Cesar De la Torre 8 years ago
parent
commit
bfe2139a09
9 changed files with 18 additions and 19 deletions
  1. +3
    -3
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs
  2. +2
    -2
      src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/ApplicationModule.cs
  3. +2
    -3
      src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/IBuyerRepository.cs
  4. +3
    -3
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs
  5. +1
    -1
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs
  6. +1
    -1
      src/Services/Ordering/Ordering.Domain/SeedWork/IRepository.cs
  7. +1
    -1
      src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs
  8. +1
    -1
      src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs
  9. +4
    -4
      test/Services/UnitTest/Ordering/Application/NewOrderCommandHandlerTest.cs

+ 3
- 3
src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs View File

@ -9,11 +9,11 @@
public class CreateOrderCommandHandler public class CreateOrderCommandHandler
: IAsyncRequestHandler<CreateOrderCommand, bool> : IAsyncRequestHandler<CreateOrderCommand, bool>
{ {
private readonly IBuyerRepository _buyerRepository;
private readonly IOrderRepository _orderRepository;
private readonly IBuyerRepository<Buyer> _buyerRepository;
private readonly IOrderRepository<Order> _orderRepository;
// Using DI to inject infrastructure persistence Repositories // Using DI to inject infrastructure persistence Repositories
public CreateOrderCommandHandler(IBuyerRepository buyerRepository, IOrderRepository orderRepository)
public CreateOrderCommandHandler(IBuyerRepository<Buyer> buyerRepository, IOrderRepository<Order> orderRepository)
{ {
if (buyerRepository == null) if (buyerRepository == null)
{ {


+ 2
- 2
src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/ApplicationModule.cs View File

@ -27,11 +27,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Autof
.InstancePerLifetimeScope(); .InstancePerLifetimeScope();
builder.RegisterType<BuyerRepository>() builder.RegisterType<BuyerRepository>()
.As<IBuyerRepository>()
.As<IBuyerRepository<Buyer>>()
.InstancePerLifetimeScope(); .InstancePerLifetimeScope();
builder.RegisterType<OrderRepository>() builder.RegisterType<OrderRepository>()
.As<IOrderRepository>()
.As<IOrderRepository<Order>>()
.InstancePerLifetimeScope(); .InstancePerLifetimeScope();
} }
} }


+ 2
- 3
src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/IBuyerRepository.cs View File

@ -1,13 +1,12 @@
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork; using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
{ {
//This is just the RepositoryContracts or Interface defined at the Domain Layer //This is just the RepositoryContracts or Interface defined at the Domain Layer
//as requisite for the Buyer Aggregate //as requisite for the Buyer Aggregate
public interface IBuyerRepository
:IAggregateRepository
public interface IBuyerRepository<T> : IRepository<T> where T : IAggregateRoot
{ {
Buyer Add(Buyer buyer); Buyer Add(Buyer buyer);


+ 3
- 3
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs View File

@ -1,11 +1,11 @@
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork; using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
{
{
//This is just the RepositoryContracts or Interface defined at the Domain Layer //This is just the RepositoryContracts or Interface defined at the Domain Layer
//as requisite for the Order Aggregate //as requisite for the Order Aggregate
public interface IOrderRepository
:IAggregateRepository
public interface IOrderRepository<T> : IRepository<T> where T : IAggregateRoot
{ {
Order Add(Order order); Order Add(Order order);
} }


+ 1
- 1
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs View File

@ -7,7 +7,7 @@ using System.Linq;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
{ {
public class Order public class Order
: Entity
: Entity, IAggregateRoot
{ {
// DDD Patterns comment // DDD Patterns comment
// Using private fields, allowed since EF Core 1.1, is a much better encapsulation // Using private fields, allowed since EF Core 1.1, is a much better encapsulation


src/Services/Ordering/Ordering.Domain/SeedWork/IAggregateRepository.cs → src/Services/Ordering/Ordering.Domain/SeedWork/IRepository.cs View File

@ -1,6 +1,6 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
{ {
public interface IAggregateRepository
public interface IRepository<T> where T : IAggregateRoot
{ {
IUnitOfWork UnitOfWork { get; } IUnitOfWork UnitOfWork { get; }
} }

+ 1
- 1
src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories
{ {
public class BuyerRepository public class BuyerRepository
: IBuyerRepository
: IBuyerRepository<Buyer>
{ {
private readonly OrderingContext _context; private readonly OrderingContext _context;


+ 1
- 1
src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories
{ {
public class OrderRepository public class OrderRepository
: IOrderRepository
: IOrderRepository<Order>
{ {
private readonly OrderingContext _context; private readonly OrderingContext _context;


+ 4
- 4
test/Services/UnitTest/Ordering/Application/NewOrderCommandHandlerTest.cs View File

@ -11,14 +11,14 @@ namespace UnitTest.Ordering.Application
{ {
public class NewOrderRequestHandlerTest public class NewOrderRequestHandlerTest
{ {
private readonly Mock<IBuyerRepository> _buyerRepositoryMock;
private readonly Mock<IOrderRepository> _orderRepositoryMock;
private readonly Mock<IBuyerRepository<Buyer>> _buyerRepositoryMock;
private readonly Mock<IOrderRepository<Order>> _orderRepositoryMock;
public NewOrderRequestHandlerTest() public NewOrderRequestHandlerTest()
{ {
_buyerRepositoryMock = new Mock<IBuyerRepository>();
_orderRepositoryMock = new Mock<IOrderRepository>();
_buyerRepositoryMock = new Mock<IBuyerRepository<Buyer>>();
_orderRepositoryMock = new Mock<IOrderRepository<Order>>();
} }
[Fact] [Fact]


Loading…
Cancel
Save