Refactoring so we enforce to have a Repository only per Aggregate
This commit is contained in:
parent
87d41be255
commit
bfe2139a09
@ -9,11 +9,11 @@
|
|||||||
public class CreateOrderCommandHandler
|
public class CreateOrderCommandHandler
|
||||||
: IAsyncRequestHandler<CreateOrderCommand, bool>
|
: IAsyncRequestHandler<CreateOrderCommand, bool>
|
||||||
{
|
{
|
||||||
private readonly IBuyerRepository _buyerRepository;
|
private readonly IBuyerRepository<Buyer> _buyerRepository;
|
||||||
private readonly IOrderRepository _orderRepository;
|
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)
|
||||||
{
|
{
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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; }
|
||||||
}
|
}
|
@ -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;
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -11,14 +11,14 @@ namespace UnitTest.Ordering.Application
|
|||||||
{
|
{
|
||||||
public class NewOrderRequestHandlerTest
|
public class NewOrderRequestHandlerTest
|
||||||
{
|
{
|
||||||
private readonly Mock<IBuyerRepository> _buyerRepositoryMock;
|
private readonly Mock<IBuyerRepository<Buyer>> _buyerRepositoryMock;
|
||||||
private readonly Mock<IOrderRepository> _orderRepositoryMock;
|
private readonly Mock<IOrderRepository<Order>> _orderRepositoryMock;
|
||||||
|
|
||||||
public NewOrderRequestHandlerTest()
|
public NewOrderRequestHandlerTest()
|
||||||
{
|
{
|
||||||
|
|
||||||
_buyerRepositoryMock = new Mock<IBuyerRepository>();
|
_buyerRepositoryMock = new Mock<IBuyerRepository<Buyer>>();
|
||||||
_orderRepositoryMock = new Mock<IOrderRepository>();
|
_orderRepositoryMock = new Mock<IOrderRepository<Order>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user