Refactoring so we enforce to have a Repository only per Aggregate

This commit is contained in:
Cesar De la Torre 2017-02-26 20:32:34 -08:00
parent 87d41be255
commit bfe2139a09
9 changed files with 18 additions and 19 deletions

View File

@ -9,11 +9,11 @@
public class CreateOrderCommandHandler
: 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
public CreateOrderCommandHandler(IBuyerRepository buyerRepository, IOrderRepository orderRepository)
public CreateOrderCommandHandler(IBuyerRepository<Buyer> buyerRepository, IOrderRepository<Order> orderRepository)
{
if (buyerRepository == null)
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,14 +11,14 @@ namespace UnitTest.Ordering.Application
{
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()
{
_buyerRepositoryMock = new Mock<IBuyerRepository>();
_orderRepositoryMock = new Mock<IOrderRepository>();
_buyerRepositoryMock = new Mock<IBuyerRepository<Buyer>>();
_orderRepositoryMock = new Mock<IOrderRepository<Order>>();
}
[Fact]