Browse Source

Remove IProductRepository

pull/819/head
Halil ibrahim Kalkan 8 years ago
parent
commit
ee536c018d
  1. 14
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs
  2. 8
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/PublicProductAppService.cs
  3. 13
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/IProductRepository.cs
  4. 30
      samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement/EfCoreProductRepository.cs
  5. 7
      samples/MicroserviceDemo/modules/product/test/ProductManagement.Application.Tests/ProductManagement/ProductAppService_Tests.cs

14
samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs

@ -1,9 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace ProductManagement namespace ProductManagement
{ {
@ -11,9 +15,9 @@ namespace ProductManagement
public class ProductAppService : ApplicationService, IProductAppService public class ProductAppService : ApplicationService, IProductAppService
{ {
private readonly ProductManager _productManager; private readonly ProductManager _productManager;
private readonly IProductRepository _productRepository; private readonly IRepository<Product, Guid> _productRepository;
public ProductAppService(ProductManager productManager, IProductRepository productRepository) public ProductAppService(ProductManager productManager, IRepository<Product, Guid> productRepository)
{ {
_productManager = productManager; _productManager = productManager;
_productRepository = productRepository; _productRepository = productRepository;
@ -23,7 +27,11 @@ namespace ProductManagement
{ {
await NormalizeMaxResultCountAsync(input); await NormalizeMaxResultCountAsync(input);
var products = await _productRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount); var products = await _productRepository
.OrderBy(input.Sorting)
.Skip(input.SkipCount)
.Take(input.MaxResultCount)
.ToListAsync();
var totalCount = await _productRepository.GetCountAsync(); var totalCount = await _productRepository.GetCountAsync();

8
samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/PublicProductAppService.cs

@ -1,15 +1,17 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace ProductManagement namespace ProductManagement
{ {
public class PublicProductAppService : ApplicationService, IPublicProductAppService public class PublicProductAppService : ApplicationService, IPublicProductAppService
{ {
private readonly IProductRepository _productRepository; private readonly IRepository<Product, Guid> _productRepository;
public PublicProductAppService(IProductRepository productRepository) public PublicProductAppService(IRepository<Product, Guid> productRepository)
{ {
_productRepository = productRepository; _productRepository = productRepository;
} }

13
samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/IProductRepository.cs

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace ProductManagement
{
public interface IProductRepository : IBasicRepository<Product, Guid>
{
Task<List<Product>> GetListAsync(string sorting, int maxResultCount, int skipCount);
}
}

30
samples/MicroserviceDemo/modules/product/src/ProductManagement.EntityFrameworkCore/ProductManagement/EfCoreProductRepository.cs

@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ProductManagement.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using System.Linq;
using System.Linq.Dynamic.Core;
using Microsoft.EntityFrameworkCore;
namespace ProductManagement
{
public class EfCoreProductRepository : EfCoreRepository<IProductManagementDbContext, Product, Guid>, IProductRepository
{
public EfCoreProductRepository(IDbContextProvider<IProductManagementDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task<List<Product>> GetListAsync(string sorting, int maxResultCount, int skipCount)
{
// TODO: refactor sorting
var products = await DbSet.OrderBy(sorting ?? "creationTime desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync();
return products;
}
}
}

7
samples/MicroserviceDemo/modules/product/test/ProductManagement.Application.Tests/ProductManagement/ProductAppService_Tests.cs

@ -1,10 +1,9 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Shouldly; using Shouldly;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories;
using Xunit; using Xunit;
namespace ProductManagement namespace ProductManagement
@ -12,13 +11,13 @@ namespace ProductManagement
public class ProductAppService_Tests : ProductManagementApplicationTestBase public class ProductAppService_Tests : ProductManagementApplicationTestBase
{ {
private readonly IProductAppService _productAppService; private readonly IProductAppService _productAppService;
private readonly IProductRepository _productRepository; private readonly IRepository<Product, Guid> _productRepository;
private readonly ProductManagementTestData _testData; private readonly ProductManagementTestData _testData;
public ProductAppService_Tests() public ProductAppService_Tests()
{ {
_productAppService = GetRequiredService<IProductAppService>(); _productAppService = GetRequiredService<IProductAppService>();
_productRepository = GetRequiredService<IProductRepository>(); _productRepository = GetRequiredService<IRepository<Product, Guid>>();
_testData = GetRequiredService<ProductManagementTestData>(); _testData = GetRequiredService<ProductManagementTestData>();
} }

Loading…
Cancel
Save