From 555c3295f1604f3e155ed743095e5d9496d14dc6 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Sat, 30 Mar 2019 15:29:32 -0400 Subject: [PATCH] Renaming CatalogServices to CatalogViewModelService - I believe this causes some confusion when people see "Service" in the Web project. We have another service in there named BasketViewModelService instead of BasketService anyways. Adding "ViewModel" to the name is a better representation of what the "services" in the Web project represent. --- src/Web/Controllers/Api/CatalogController.cs | 6 +++--- ...logService.cs => ICatalogViewModelService.cs} | 2 +- src/Web/Pages/Index.cshtml.cs | 8 ++++---- ...rvice.cs => CachedCatalogViewModelService.cs} | 16 ++++++++-------- ...alogService.cs => CatalogViewModelService.cs} | 8 ++++---- src/Web/Startup.cs | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) rename src/Web/Interfaces/{ICatalogService.cs => ICatalogViewModelService.cs} (90%) rename src/Web/Services/{CachedCatalogService.cs => CachedCatalogViewModelService.cs} (73%) rename src/Web/Services/{CatalogService.cs => CatalogViewModelService.cs} (94%) diff --git a/src/Web/Controllers/Api/CatalogController.cs b/src/Web/Controllers/Api/CatalogController.cs index 1adc783..cbf3444 100644 --- a/src/Web/Controllers/Api/CatalogController.cs +++ b/src/Web/Controllers/Api/CatalogController.cs @@ -6,15 +6,15 @@ namespace Microsoft.eShopWeb.Web.Controllers.Api { public class CatalogController : BaseApiController { - private readonly ICatalogService _catalogService; + private readonly ICatalogViewModelService _catalogViewModelService; - public CatalogController(ICatalogService catalogService) => _catalogService = catalogService; + public CatalogController(ICatalogViewModelService catalogViewModelService) => _catalogViewModelService = catalogViewModelService; [HttpGet] public async Task List(int? brandFilterApplied, int? typesFilterApplied, int? page) { var itemsPage = 10; - var catalogModel = await _catalogService.GetCatalogItems(page ?? 0, itemsPage, brandFilterApplied, typesFilterApplied); + var catalogModel = await _catalogViewModelService.GetCatalogItems(page ?? 0, itemsPage, brandFilterApplied, typesFilterApplied); return Ok(catalogModel); } } diff --git a/src/Web/Interfaces/ICatalogService.cs b/src/Web/Interfaces/ICatalogViewModelService.cs similarity index 90% rename from src/Web/Interfaces/ICatalogService.cs rename to src/Web/Interfaces/ICatalogViewModelService.cs index 82765f5..a229bde 100644 --- a/src/Web/Interfaces/ICatalogService.cs +++ b/src/Web/Interfaces/ICatalogViewModelService.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; namespace Microsoft.eShopWeb.Web.Services { - public interface ICatalogService + public interface ICatalogViewModelService { Task GetCatalogItems(int pageIndex, int itemsPage, int? brandId, int? typeId); Task> GetBrands(); diff --git a/src/Web/Pages/Index.cshtml.cs b/src/Web/Pages/Index.cshtml.cs index 7e32c30..5c52559 100644 --- a/src/Web/Pages/Index.cshtml.cs +++ b/src/Web/Pages/Index.cshtml.cs @@ -7,18 +7,18 @@ namespace Microsoft.eShopWeb.Web.Pages { public class IndexModel : PageModel { - private readonly ICatalogService _catalogService; + private readonly ICatalogViewModelService _catalogViewModelService; - public IndexModel(ICatalogService catalogService) + public IndexModel(ICatalogViewModelService catalogViewModelService) { - _catalogService = catalogService; + _catalogViewModelService = catalogViewModelService; } public CatalogIndexViewModel CatalogModel { get; set; } = new CatalogIndexViewModel(); public async Task OnGet(CatalogIndexViewModel catalogModel, int? pageId) { - CatalogModel = await _catalogService.GetCatalogItems(pageId ?? 0, Constants.ITEMS_PER_PAGE, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied); + CatalogModel = await _catalogViewModelService.GetCatalogItems(pageId ?? 0, Constants.ITEMS_PER_PAGE, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied); } diff --git a/src/Web/Services/CachedCatalogService.cs b/src/Web/Services/CachedCatalogViewModelService.cs similarity index 73% rename from src/Web/Services/CachedCatalogService.cs rename to src/Web/Services/CachedCatalogViewModelService.cs index 94e513d..0aebeca 100644 --- a/src/Web/Services/CachedCatalogService.cs +++ b/src/Web/Services/CachedCatalogViewModelService.cs @@ -7,20 +7,20 @@ using System; namespace Microsoft.eShopWeb.Web.Services { - public class CachedCatalogService : ICatalogService + public class CachedCatalogViewModelService : ICatalogViewModelService { private readonly IMemoryCache _cache; - private readonly CatalogService _catalogService; + private readonly CatalogViewModelService _catalogViewModelService; private static readonly string _brandsKey = "brands"; private static readonly string _typesKey = "types"; private static readonly string _itemsKeyTemplate = "items-{0}-{1}-{2}-{3}"; private static readonly TimeSpan _defaultCacheDuration = TimeSpan.FromSeconds(30); - public CachedCatalogService(IMemoryCache cache, - CatalogService catalogService) + public CachedCatalogViewModelService(IMemoryCache cache, + CatalogViewModelService catalogViewModelService) { _cache = cache; - _catalogService = catalogService; + _catalogViewModelService = catalogViewModelService; } public async Task> GetBrands() @@ -28,7 +28,7 @@ namespace Microsoft.eShopWeb.Web.Services return await _cache.GetOrCreateAsync(_brandsKey, async entry => { entry.SlidingExpiration = _defaultCacheDuration; - return await _catalogService.GetBrands(); + return await _catalogViewModelService.GetBrands(); }); } @@ -38,7 +38,7 @@ namespace Microsoft.eShopWeb.Web.Services return await _cache.GetOrCreateAsync(cacheKey, async entry => { entry.SlidingExpiration = _defaultCacheDuration; - return await _catalogService.GetCatalogItems(pageIndex, itemsPage, brandId, typeId); + return await _catalogViewModelService.GetCatalogItems(pageIndex, itemsPage, brandId, typeId); }); } @@ -47,7 +47,7 @@ namespace Microsoft.eShopWeb.Web.Services return await _cache.GetOrCreateAsync(_typesKey, async entry => { entry.SlidingExpiration = _defaultCacheDuration; - return await _catalogService.GetTypes(); + return await _catalogViewModelService.GetTypes(); }); } } diff --git a/src/Web/Services/CatalogService.cs b/src/Web/Services/CatalogViewModelService.cs similarity index 94% rename from src/Web/Services/CatalogService.cs rename to src/Web/Services/CatalogViewModelService.cs index 5229aa5..20e8bef 100644 --- a/src/Web/Services/CatalogService.cs +++ b/src/Web/Services/CatalogViewModelService.cs @@ -15,22 +15,22 @@ namespace Microsoft.eShopWeb.Web.Services /// This is a UI-specific service so belongs in UI project. It does not contain any business logic and works /// with UI-specific types (view models and SelectListItem types). /// - public class CatalogService : ICatalogService + public class CatalogViewModelService : ICatalogViewModelService { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IAsyncRepository _itemRepository; private readonly IAsyncRepository _brandRepository; private readonly IAsyncRepository _typeRepository; private readonly IUriComposer _uriComposer; - public CatalogService( + public CatalogViewModelService( ILoggerFactory loggerFactory, IAsyncRepository itemRepository, IAsyncRepository brandRepository, IAsyncRepository typeRepository, IUriComposer uriComposer) { - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.CreateLogger(); _itemRepository = itemRepository; _brandRepository = brandRepository; _typeRepository = typeRepository; diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index a8c41a8..742a926 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -87,12 +87,12 @@ namespace Microsoft.eShopWeb.Web services.AddScoped(typeof(IAsyncRepository<>), typeof(EfRepository<>)); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.Configure(Configuration); services.AddSingleton(new UriComposer(Configuration.Get()));