Update Specification and other packages to latest version (#582)
* Updating repositories and specification version Need to fix broken tests * removing test that would just be testing mocked result now * Refactored from IAsyncRepository and removed it. Tests pass. * Update packages
This commit is contained in:
@@ -10,12 +10,16 @@ namespace Microsoft.eShopWeb.Web.Configuration
|
||||
{
|
||||
public static class ConfigureCoreServices
|
||||
{
|
||||
public static IServiceCollection AddCoreServices(this IServiceCollection services, IConfiguration configuration)
|
||||
public static IServiceCollection AddCoreServices(this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddScoped(typeof(IAsyncRepository<>), typeof(EfRepository<>));
|
||||
//services.AddScoped(typeof(IAsyncRepository<>), typeof(EfRepository<>));
|
||||
services.AddScoped(typeof(IReadRepository<>), typeof(EfRepository<>));
|
||||
services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
|
||||
|
||||
services.AddScoped<IBasketService, BasketService>();
|
||||
services.AddScoped<IOrderService, OrderService>();
|
||||
services.AddScoped<IOrderRepository, OrderRepository>();
|
||||
//services.AddScoped<IOrderRepository, OrderRepository>();
|
||||
services.AddSingleton<IUriComposer>(new UriComposer(configuration.Get<CatalogSettings>()));
|
||||
services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
|
||||
services.AddTransient<IEmailSender, EmailSender>();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MediatR;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Specifications;
|
||||
using Microsoft.eShopWeb.Web.ViewModels;
|
||||
@@ -11,14 +12,15 @@ namespace Microsoft.eShopWeb.Web.Features.MyOrders
|
||||
{
|
||||
public class GetMyOrdersHandler : IRequestHandler<GetMyOrders, IEnumerable<OrderViewModel>>
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly IReadRepository<Order> _orderRepository;
|
||||
|
||||
public GetMyOrdersHandler(IOrderRepository orderRepository)
|
||||
public GetMyOrdersHandler(IReadRepository<Order> orderRepository)
|
||||
{
|
||||
_orderRepository = orderRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<OrderViewModel>> Handle(GetMyOrders request, CancellationToken cancellationToken)
|
||||
public async Task<IEnumerable<OrderViewModel>> Handle(GetMyOrders request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var specification = new CustomerOrdersWithItemsSpecification(request.UserName);
|
||||
var orders = await _orderRepository.ListAsync(specification, cancellationToken);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MediatR;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Specifications;
|
||||
using Microsoft.eShopWeb.Web.ViewModels;
|
||||
@@ -10,17 +11,18 @@ namespace Microsoft.eShopWeb.Web.Features.OrderDetails
|
||||
{
|
||||
public class GetOrderDetailsHandler : IRequestHandler<GetOrderDetails, OrderViewModel>
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly IReadRepository<Order> _orderRepository;
|
||||
|
||||
public GetOrderDetailsHandler(IOrderRepository orderRepository)
|
||||
public GetOrderDetailsHandler(IReadRepository<Order> orderRepository)
|
||||
{
|
||||
_orderRepository = orderRepository;
|
||||
}
|
||||
|
||||
public async Task<OrderViewModel> Handle(GetOrderDetails request, CancellationToken cancellationToken)
|
||||
public async Task<OrderViewModel> Handle(GetOrderDetails request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var customerOrders = await _orderRepository.ListAsync(new CustomerOrdersWithItemsSpecification(request.UserName), cancellationToken);
|
||||
var order = customerOrders.FirstOrDefault(o => o.Id == request.OrderId);
|
||||
var spec = new OrderWithItemsByIdSpec(request.OrderId);
|
||||
var order = await _orderRepository.GetBySpecAsync(spec, cancellationToken);
|
||||
|
||||
if (order == null)
|
||||
{
|
||||
|
||||
@@ -12,12 +12,12 @@ namespace Microsoft.eShopWeb.Web.Services
|
||||
{
|
||||
public class BasketViewModelService : IBasketViewModelService
|
||||
{
|
||||
private readonly IAsyncRepository<Basket> _basketRepository;
|
||||
private readonly IRepository<Basket> _basketRepository;
|
||||
private readonly IUriComposer _uriComposer;
|
||||
private readonly IAsyncRepository<CatalogItem> _itemRepository;
|
||||
private readonly IRepository<CatalogItem> _itemRepository;
|
||||
|
||||
public BasketViewModelService(IAsyncRepository<Basket> basketRepository,
|
||||
IAsyncRepository<CatalogItem> itemRepository,
|
||||
public BasketViewModelService(IRepository<Basket> basketRepository,
|
||||
IRepository<CatalogItem> itemRepository,
|
||||
IUriComposer uriComposer)
|
||||
{
|
||||
_basketRepository = basketRepository;
|
||||
@@ -28,7 +28,7 @@ namespace Microsoft.eShopWeb.Web.Services
|
||||
public async Task<BasketViewModel> GetOrCreateBasketForUser(string userName)
|
||||
{
|
||||
var basketSpec = new BasketWithItemsSpecification(userName);
|
||||
var basket = (await _basketRepository.FirstOrDefaultAsync(basketSpec));
|
||||
var basket = (await _basketRepository.GetBySpecAsync(basketSpec));
|
||||
|
||||
if (basket == null)
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace Microsoft.eShopWeb.Web.Services
|
||||
{
|
||||
public class CatalogItemViewModelService : ICatalogItemViewModelService
|
||||
{
|
||||
private readonly IAsyncRepository<CatalogItem> _catalogItemRepository;
|
||||
private readonly IRepository<CatalogItem> _catalogItemRepository;
|
||||
|
||||
public CatalogItemViewModelService(IAsyncRepository<CatalogItem> catalogItemRepository)
|
||||
public CatalogItemViewModelService(IRepository<CatalogItem> catalogItemRepository)
|
||||
{
|
||||
_catalogItemRepository = catalogItemRepository;
|
||||
}
|
||||
|
||||
@@ -18,16 +18,16 @@ namespace Microsoft.eShopWeb.Web.Services
|
||||
public class CatalogViewModelService : ICatalogViewModelService
|
||||
{
|
||||
private readonly ILogger<CatalogViewModelService> _logger;
|
||||
private readonly IAsyncRepository<CatalogItem> _itemRepository;
|
||||
private readonly IAsyncRepository<CatalogBrand> _brandRepository;
|
||||
private readonly IAsyncRepository<CatalogType> _typeRepository;
|
||||
private readonly IRepository<CatalogItem> _itemRepository;
|
||||
private readonly IRepository<CatalogBrand> _brandRepository;
|
||||
private readonly IRepository<CatalogType> _typeRepository;
|
||||
private readonly IUriComposer _uriComposer;
|
||||
|
||||
public CatalogViewModelService(
|
||||
ILoggerFactory loggerFactory,
|
||||
IAsyncRepository<CatalogItem> itemRepository,
|
||||
IAsyncRepository<CatalogBrand> brandRepository,
|
||||
IAsyncRepository<CatalogType> typeRepository,
|
||||
IRepository<CatalogItem> itemRepository,
|
||||
IRepository<CatalogBrand> brandRepository,
|
||||
IRepository<CatalogType> typeRepository,
|
||||
IUriComposer uriComposer)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger<CatalogViewModelService>();
|
||||
@@ -80,7 +80,7 @@ namespace Microsoft.eShopWeb.Web.Services
|
||||
public async Task<IEnumerable<SelectListItem>> GetBrands()
|
||||
{
|
||||
_logger.LogInformation("GetBrands called.");
|
||||
var brands = await _brandRepository.ListAllAsync();
|
||||
var brands = await _brandRepository.ListAsync();
|
||||
|
||||
var items = brands
|
||||
.Select(brand => new SelectListItem() { Value = brand.Id.ToString(), Text = brand.Brand })
|
||||
@@ -96,7 +96,7 @@ namespace Microsoft.eShopWeb.Web.Services
|
||||
public async Task<IEnumerable<SelectListItem>> GetTypes()
|
||||
{
|
||||
_logger.LogInformation("GetTypes called.");
|
||||
var types = await _typeRepository.ListAllAsync();
|
||||
var types = await _typeRepository.ListAsync();
|
||||
|
||||
var items = types
|
||||
.Select(type => new SelectListItem() { Value = type.Id.ToString(), Text = type.Type })
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Ardalis.ApiEndpoints" Version="2.0.0" />
|
||||
<PackageReference Include="Ardalis.ListStartupServices" Version="1.1.3" />
|
||||
<PackageReference Include="Ardalis.Specification" Version="4.1.0" />
|
||||
<PackageReference Include="Ardalis.Specification" Version="5.2.0" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
|
||||
|
||||
<PackageReference Include="MediatR" Version="9.0.0" />
|
||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
|
||||
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" Condition="'$(Configuration)'=='Release'" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.8.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.11.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.113" />
|
||||
|
||||
Reference in New Issue
Block a user