Merge pull request #120 from FDUdannychen/feature/ddd
use non generic repository interface
This commit is contained in:
commit
5432936201
@ -24,12 +24,12 @@
|
|||||||
public class CreateOrderCommandHandler
|
public class CreateOrderCommandHandler
|
||||||
: IAsyncRequestHandler<CreateOrderCommand, bool>
|
: IAsyncRequestHandler<CreateOrderCommand, bool>
|
||||||
{
|
{
|
||||||
private readonly IBuyerRepository<Buyer> _buyerRepository;
|
private readonly IBuyerRepository _buyerRepository;
|
||||||
private readonly IOrderRepository<Order> _orderRepository;
|
private readonly IOrderRepository _orderRepository;
|
||||||
private readonly IIdentityService _identityService;
|
private readonly IIdentityService _identityService;
|
||||||
|
|
||||||
// Using DI to inject infrastructure persistence Repositories
|
// Using DI to inject infrastructure persistence Repositories
|
||||||
public CreateOrderCommandHandler(IBuyerRepository<Buyer> buyerRepository, IOrderRepository<Order> orderRepository, IIdentityService identityService)
|
public CreateOrderCommandHandler(IBuyerRepository buyerRepository, IOrderRepository orderRepository, IIdentityService identityService)
|
||||||
{
|
{
|
||||||
_buyerRepository = buyerRepository ?? throw new ArgumentNullException(nameof(buyerRepository));
|
_buyerRepository = buyerRepository ?? throw new ArgumentNullException(nameof(buyerRepository));
|
||||||
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
||||||
|
@ -27,11 +27,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Autof
|
|||||||
.InstancePerLifetimeScope();
|
.InstancePerLifetimeScope();
|
||||||
|
|
||||||
builder.RegisterType<BuyerRepository>()
|
builder.RegisterType<BuyerRepository>()
|
||||||
.As<IBuyerRepository<Buyer>>()
|
.As<IBuyerRepository>()
|
||||||
.InstancePerLifetimeScope();
|
.InstancePerLifetimeScope();
|
||||||
|
|
||||||
builder.RegisterType<OrderRepository>()
|
builder.RegisterType<OrderRepository>()
|
||||||
.As<IOrderRepository<Order>>()
|
.As<IOrderRepository>()
|
||||||
.InstancePerLifetimeScope();
|
.InstancePerLifetimeScope();
|
||||||
|
|
||||||
builder.RegisterType<RequestManager>()
|
builder.RegisterType<RequestManager>()
|
||||||
|
@ -6,7 +6,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
//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<T> : IRepository<T> where T : IAggregateRoot
|
public interface IBuyerRepository : IRepository<Buyer>
|
||||||
{
|
{
|
||||||
Buyer Add(Buyer buyer);
|
Buyer Add(Buyer buyer);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
//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<T> : IRepository<T> where T : IAggregateRoot
|
public interface IOrderRepository : IRepository<Order>
|
||||||
{
|
{
|
||||||
Order Add(Order order);
|
Order Add(Order order);
|
||||||
}
|
}
|
||||||
|
@ -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<Buyer>
|
: IBuyerRepository
|
||||||
{
|
{
|
||||||
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<Order>
|
: IOrderRepository
|
||||||
{
|
{
|
||||||
private readonly OrderingContext _context;
|
private readonly OrderingContext _context;
|
||||||
|
|
||||||
|
@ -15,15 +15,15 @@ namespace UnitTest.Ordering.Application
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
public class NewOrderRequestHandlerTest
|
public class NewOrderRequestHandlerTest
|
||||||
{
|
{
|
||||||
private readonly Mock<IBuyerRepository<Buyer>> _buyerRepositoryMock;
|
private readonly Mock<IBuyerRepository> _buyerRepositoryMock;
|
||||||
private readonly Mock<IOrderRepository<Order>> _orderRepositoryMock;
|
private readonly Mock<IOrderRepository> _orderRepositoryMock;
|
||||||
private readonly Mock<IIdentityService> _identityServiceMock;
|
private readonly Mock<IIdentityService> _identityServiceMock;
|
||||||
|
|
||||||
public NewOrderRequestHandlerTest()
|
public NewOrderRequestHandlerTest()
|
||||||
{
|
{
|
||||||
|
|
||||||
_buyerRepositoryMock = new Mock<IBuyerRepository<Buyer>>();
|
_buyerRepositoryMock = new Mock<IBuyerRepository>();
|
||||||
_orderRepositoryMock = new Mock<IOrderRepository<Order>>();
|
_orderRepositoryMock = new Mock<IOrderRepository>();
|
||||||
_identityServiceMock = new Mock<IIdentityService>();
|
_identityServiceMock = new Mock<IIdentityService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user