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
 | 
			
		||||
        : 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)
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,11 @@
 | 
			
		||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
 | 
			
		||||
 | 
			
		||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
 | 
			
		||||
{ 
 | 
			
		||||
{
 | 
			
		||||
    //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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
 | 
			
		||||
{
 | 
			
		||||
    public interface IAggregateRepository
 | 
			
		||||
    public interface IRepository<T> where T : IAggregateRoot
 | 
			
		||||
    {
 | 
			
		||||
        IUnitOfWork UnitOfWork { get; }
 | 
			
		||||
    }
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,7 @@ using System;
 | 
			
		||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories
 | 
			
		||||
{
 | 
			
		||||
    public class OrderRepository
 | 
			
		||||
        : IOrderRepository
 | 
			
		||||
        : IOrderRepository<Order> 
 | 
			
		||||
    {
 | 
			
		||||
        private readonly OrderingContext _context;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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]
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user