Refactored namespace statements in catalog.api project

This commit is contained in:
Sumit Ghosh 2021-10-11 18:44:14 +05:30
parent a598bfde6c
commit 986262a833
32 changed files with 1782 additions and 1819 deletions

View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API
namespace Microsoft.eShopOnContainers.Services.Catalog.API;
public class CatalogSettings
{
public class CatalogSettings
{
public string PicBaseUrl { get; set; }
public string EventBusConnection { get; set; }
@ -9,5 +9,4 @@
public bool UseCustomizationData { get; set; }
public bool AzureStorageEnabled { get; set; }
}
}

View File

@ -1,10 +1,9 @@
using Microsoft.eShopOnContainers.Services.Catalog.API.Model;
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers;
[Route("api/v1/[controller]")]
[ApiController]
public class CatalogController : ControllerBase
{
[Route("api/v1/[controller]")]
[ApiController]
public class CatalogController : ControllerBase
{
private readonly CatalogContext _catalogContext;
private readonly CatalogSettings _settings;
private readonly ICatalogIntegrationEventService _catalogIntegrationEventService;
@ -298,5 +297,4 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
return items;
}
}
}

View File

@ -1,13 +1,11 @@
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers;
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
public class HomeController : Controller
{
public class HomeController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
return new RedirectResult("~/swagger");
}
}
}

View File

@ -1,9 +1,9 @@
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers;
[ApiController]
public class PicController : ControllerBase
{
[ApiController]
public class PicController : ControllerBase
{
private readonly IWebHostEnvironment _env;
private readonly CatalogContext _catalogContext;
@ -83,5 +83,4 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
return mimetype;
}
}
}

View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model;
public static class CatalogItemExtensions
{
public static class CatalogItemExtensions
{
public static void FillProductUrl(this CatalogItem item, string picBaseUrl, bool azureStorageEnabled)
{
if (item != null)
@ -11,5 +11,4 @@
: picBaseUrl.Replace("[0]", item.Id.ToString());
}
}
}
}

View File

@ -1,7 +1,7 @@
namespace Catalog.API.Extensions
namespace Catalog.API.Extensions;
public static class HostExtensions
{
public static class HostExtensions
{
public static bool IsInKubernetes(this IHost host)
{
var cfg = host.Services.GetService<IConfiguration>();
@ -67,5 +67,4 @@
context.Database.Migrate();
seeder(context, services);
}
}
}

View File

@ -1,7 +1,7 @@
namespace Catalog.API.Extensions
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Extensions;
public static class LinqSelectExtensions
{
public static class LinqSelectExtensions
{
public static IEnumerable<SelectTryResult<TSource, TResult>> SelectTry<TSource, TResult>(this IEnumerable<TSource> enumerable, Func<TSource, TResult> selector)
{
foreach (TSource element in enumerable)
@ -42,5 +42,4 @@
public TResult Result { get; private set; }
public Exception CaughtException { get; private set; }
}
}
}

View File

@ -1,7 +1,7 @@
namespace Catalog.API.Extensions
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Extensions;
public static class WebHostExtensions
{
public static class WebHostExtensions
{
public static bool IsInKubernetes(this IWebHost host)
{
var cfg = host.Services.GetService<IConfiguration>();
@ -67,5 +67,4 @@
context.Database.Migrate();
seeder(context, services);
}
}
}

View File

@ -2,10 +2,10 @@
global using Azure.Identity;
global using Autofac.Extensions.DependencyInjection;
global using Autofac;
global using Catalog.API.Extensions;
global using Catalog.API.Infrastructure.ActionResults;
global using Catalog.API.Infrastructure.Exceptions;
global using global::Catalog.API.IntegrationEvents;
global using Microsoft.eShopOnContainers.Services.Catalog.API.Extensions;
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.ActionResults;
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.Exceptions;
global using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents;
global using Grpc.Core;
global using Microsoft.AspNetCore.Hosting;
global using Microsoft.AspNetCore.Http;
@ -48,7 +48,7 @@ global using System.Net;
global using System.Text.RegularExpressions;
global using System.Threading.Tasks;
global using System;
global using global::Catalog.API.Infrastructure.Filters;
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.Filters;
global using HealthChecks.UI.Client;
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
global using Microsoft.Azure.ServiceBus;

View File

@ -1,13 +1,13 @@
using CatalogApi;
using static CatalogApi.Catalog;
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Grpc
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Grpc;
public class CatalogService : CatalogBase
{
public class CatalogService : CatalogBase
{
private readonly CatalogContext _catalogContext;
private readonly CatalogSettings _settings;
private readonly Extensions.Logging.ILogger _logger;
private readonly Microsoft.Extensions.Logging.ILogger _logger;
public CatalogService(CatalogContext dbContext, IOptions<CatalogSettings> settings, ILogger<CatalogService> logger)
{
@ -173,5 +173,4 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Grpc
return items;
}
}
}

View File

@ -1,11 +1,10 @@
namespace Catalog.API.Infrastructure.ActionResults
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.ActionResults;
public class InternalServerErrorObjectResult : ObjectResult
{
public class InternalServerErrorObjectResult : ObjectResult
{
public InternalServerErrorObjectResult(object error)
: base(error)
{
StatusCode = StatusCodes.Status500InternalServerError;
}
}
}

View File

@ -1,9 +1,9 @@
using Microsoft.eShopOnContainers.Services.Catalog.API.Model;
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
public class CatalogContext : DbContext
{
public class CatalogContext : DbContext
{
public CatalogContext(DbContextOptions<CatalogContext> options) : base(options)
{
}
@ -17,11 +17,11 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure
builder.ApplyConfiguration(new CatalogTypeEntityTypeConfiguration());
builder.ApplyConfiguration(new CatalogItemEntityTypeConfiguration());
}
}
}
public class CatalogContextDesignFactory : IDesignTimeDbContextFactory<CatalogContext>
{
public class CatalogContextDesignFactory : IDesignTimeDbContextFactory<CatalogContext>
{
public CatalogContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<CatalogContext>()
@ -29,5 +29,4 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure
return new CatalogContext(optionsBuilder.Options);
}
}
}

View File

@ -1,9 +1,9 @@
using Microsoft.eShopOnContainers.Services.Catalog.API.Model;
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
public class CatalogContextSeed
{
public class CatalogContextSeed
{
public async Task SeedAsync(CatalogContext context, IWebHostEnvironment env, IOptions<CatalogSettings> settings, ILogger<CatalogContextSeed> logger)
{
var policy = CreatePolicy(logger, nameof(CatalogContextSeed));
@ -367,5 +367,4 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure
}
);
}
}
}

View File

@ -1,8 +1,8 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.EntityConfigurations
{
class CatalogBrandEntityTypeConfiguration
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.EntityConfigurations;
class CatalogBrandEntityTypeConfiguration
: IEntityTypeConfiguration<CatalogBrand>
{
{
public void Configure(EntityTypeBuilder<CatalogBrand> builder)
{
builder.ToTable("CatalogBrand");
@ -17,5 +17,4 @@
.IsRequired()
.HasMaxLength(100);
}
}
}

View File

@ -1,8 +1,8 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.EntityConfigurations
{
class CatalogItemEntityTypeConfiguration
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.EntityConfigurations;
class CatalogItemEntityTypeConfiguration
: IEntityTypeConfiguration<CatalogItem>
{
{
public void Configure(EntityTypeBuilder<CatalogItem> builder)
{
builder.ToTable("Catalog");
@ -31,5 +31,4 @@
.WithMany()
.HasForeignKey(ci => ci.CatalogTypeId);
}
}
}

View File

@ -1,8 +1,8 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.EntityConfigurations
{
class CatalogTypeEntityTypeConfiguration
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.EntityConfigurations;
class CatalogTypeEntityTypeConfiguration
: IEntityTypeConfiguration<CatalogType>
{
{
public void Configure(EntityTypeBuilder<CatalogType> builder)
{
builder.ToTable("CatalogType");
@ -17,5 +17,4 @@
.IsRequired()
.HasMaxLength(100);
}
}
}

View File

@ -1,10 +1,10 @@
namespace Catalog.API.Infrastructure.Exceptions
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.Exceptions;
/// <summary>
/// Exception type for app exceptions
/// </summary>
public class CatalogDomainException : Exception
{
/// <summary>
/// Exception type for app exceptions
/// </summary>
public class CatalogDomainException : Exception
{
public CatalogDomainException()
{ }
@ -15,5 +15,4 @@
public CatalogDomainException(string message, Exception innerException)
: base(message, innerException)
{ }
}
}

View File

@ -1,7 +1,7 @@
namespace Catalog.API.Infrastructure.Filters
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.Filters;
public class HttpGlobalExceptionFilter : IExceptionFilter
{
public class HttpGlobalExceptionFilter : IExceptionFilter
{
private readonly IWebHostEnvironment env;
private readonly ILogger<HttpGlobalExceptionFilter> logger;
@ -55,5 +55,4 @@
public object DeveloperMessage { get; set; }
}
}
}

View File

@ -1,7 +1,7 @@
namespace Catalog.API.IntegrationEvents
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents;
public class CatalogIntegrationEventService : ICatalogIntegrationEventService, IDisposable
{
public class CatalogIntegrationEventService : ICatalogIntegrationEventService, IDisposable
{
private readonly Func<DbConnection, IIntegrationEventLogService> _integrationEventLogServiceFactory;
private readonly IEventBus _eventBus;
private readonly CatalogContext _catalogContext;
@ -71,5 +71,4 @@
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@ -1,9 +1,8 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling
{
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling;
public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler :
public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler :
IIntegrationEventHandler<OrderStatusChangedToAwaitingValidationIntegrationEvent>
{
{
private readonly CatalogContext _catalogContext;
private readonly ICatalogIntegrationEventService _catalogIntegrationEventService;
private readonly ILogger<OrderStatusChangedToAwaitingValidationIntegrationEventHandler> _logger;
@ -44,5 +43,4 @@
}
}
}
}

View File

@ -1,8 +1,8 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling
{
public class OrderStatusChangedToPaidIntegrationEventHandler :
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling;
public class OrderStatusChangedToPaidIntegrationEventHandler :
IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>
{
{
private readonly CatalogContext _catalogContext;
private readonly ILogger<OrderStatusChangedToPaidIntegrationEventHandler> _logger;
@ -32,5 +32,4 @@
}
}
}
}

View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
public record OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent
{
public record OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public IEnumerable<OrderStockItem> OrderStockItems { get; }
@ -11,10 +11,10 @@
OrderId = orderId;
OrderStockItems = orderStockItems;
}
}
}
public record OrderStockItem
{
public record OrderStockItem
{
public int ProductId { get; }
public int Units { get; }
@ -23,5 +23,4 @@
ProductId = productId;
Units = units;
}
}
}

View File

@ -1,10 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using System.Collections.Generic;
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
public record OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent
{
public record OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public IEnumerable<OrderStockItem> OrderStockItems { get; }
@ -14,5 +11,4 @@
OrderId = orderId;
OrderStockItems = orderStockItems;
}
}
}

View File

@ -1,9 +1,8 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
public record OrderStockConfirmedIntegrationEvent : IntegrationEvent
{
public record OrderStockConfirmedIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public OrderStockConfirmedIntegrationEvent(int orderId) => OrderId = orderId;
}
}

View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
public record OrderStockRejectedIntegrationEvent : IntegrationEvent
{
public record OrderStockRejectedIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public List<ConfirmedOrderStockItem> OrderStockItems { get; }
@ -12,10 +12,10 @@
OrderId = orderId;
OrderStockItems = orderStockItems;
}
}
}
public record ConfirmedOrderStockItem
{
public record ConfirmedOrderStockItem
{
public int ProductId { get; }
public bool HasStock { get; }
@ -24,5 +24,4 @@
ProductId = productId;
HasStock = hasStock;
}
}
}

View File

@ -1,10 +1,10 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
// Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be past tense
// An Integration Event is an event that can cause side effects to other microservices, Bounded-Contexts or external systems.
public record ProductPriceChangedIntegrationEvent : IntegrationEvent
{
// Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be past tense
// An Integration Event is an event that can cause side effects to other microservices, Bounded-Contexts or external systems.
public record ProductPriceChangedIntegrationEvent : IntegrationEvent
{
public int ProductId { get; private init; }
public decimal NewPrice { get; private init; }
@ -17,5 +17,4 @@
NewPrice = newPrice;
OldPrice = oldPrice;
}
}
}

View File

@ -1,8 +1,7 @@
namespace Catalog.API.IntegrationEvents
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents;
public interface ICatalogIntegrationEventService
{
public interface ICatalogIntegrationEventService
{
Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt);
Task PublishThroughEventBusAsync(IntegrationEvent evt);
}
}

View File

@ -1,9 +1,8 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model;
public class CatalogBrand
{
public class CatalogBrand
{
public int Id { get; set; }
public string Brand { get; set; }
}
}

View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model;
public class CatalogItem
{
public class CatalogItem
{
public int Id { get; set; }
public string Name { get; set; }
@ -96,5 +96,4 @@
return this.AvailableStock - original;
}
}
}

View File

@ -1,9 +1,8 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model;
public class CatalogType
{
public class CatalogType
{
public int Id { get; set; }
public string Type { get; set; }
}
}

View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API
namespace Microsoft.eShopOnContainers.Services.Catalog.API;
public class Startup
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
@ -89,10 +89,10 @@
eventBus.Subscribe<OrderStatusChangedToAwaitingValidationIntegrationEvent, OrderStatusChangedToAwaitingValidationIntegrationEventHandler>();
eventBus.Subscribe<OrderStatusChangedToPaidIntegrationEvent, OrderStatusChangedToPaidIntegrationEventHandler>();
}
}
}
public static class CustomExtensionMethods
{
public static class CustomExtensionMethods
{
public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration)
{
services.AddApplicationInsightsTelemetry(configuration);
@ -330,5 +330,4 @@
return services;
}
}
}

View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.ViewModel
namespace Microsoft.eShopOnContainers.Services.Catalog.API.ViewModel;
public class PaginatedItemsViewModel<TEntity> where TEntity : class
{
public class PaginatedItemsViewModel<TEntity> where TEntity : class
{
public int PageIndex { get; private set; }
public int PageSize { get; private set; }
@ -17,5 +17,4 @@
Count = count;
Data = data;
}
}
}