Use file-scoped namespaces

This commit is contained in:
Sumit Ghosh 2021-08-12 18:56:38 +05:30
parent 5157b01e81
commit 76ddee7756
31 changed files with 955 additions and 1150 deletions

View File

@ -1,11 +1,5 @@
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server
{
public class AuthorizationHeaderParameterOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
@ -30,4 +24,3 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server
}
}
}
}

View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Basket.API
{
namespace Microsoft.eShopOnContainers.Services.Basket.API;
public class BasketSettings
{
public string ConnectionString { get; set; }
}
}

View File

@ -1,18 +1,5 @@
using Basket.API.IntegrationEvents.Events;
using Basket.API.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Net;
using System.Security.Claims;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
{
[Route("api/v1/[controller]")]
[Authorize]
[ApiController]
@ -100,4 +87,3 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
await _repository.DeleteBasketAsync(id);
}
}
}

View File

@ -1,7 +1,5 @@
using Microsoft.AspNetCore.Mvc;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
{
public class HomeController : Controller
{
// GET: /<controller>/
@ -10,4 +8,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
return new RedirectResult("~/swagger");
}
}
}

View File

@ -1,12 +1,4 @@
using Grpc.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.Extensions.Logging;
using System.Linq;
using System.Threading.Tasks;
namespace GrpcBasket
{
namespace GrpcBasket;
public class BasketService : Basket.BasketBase
{
private readonly IBasketRepository _repository;
@ -99,4 +91,3 @@ namespace GrpcBasket
return response;
}
}
}

View File

@ -1,8 +1,5 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Basket.API.Infrastructure.ActionResults;
namespace Basket.API.Infrastructure.ActionResults
{
public class InternalServerErrorObjectResult : ObjectResult
{
public InternalServerErrorObjectResult(object error)
@ -11,4 +8,4 @@ namespace Basket.API.Infrastructure.ActionResults
StatusCode = StatusCodes.Status500InternalServerError;
}
}
}

View File

@ -1,10 +1,5 @@
using System;
namespace Basket.API.Infrastructure.Exceptions;
namespace Basket.API.Infrastructure.Exceptions
{
/// <summary>
/// Exception type for app exceptions
/// </summary>
public class BasketDomainException : Exception
{
public BasketDomainException()
@ -18,4 +13,4 @@ namespace Basket.API.Infrastructure.Exceptions
: base(message, innerException)
{ }
}
}

View File

@ -1,8 +1,5 @@
using Microsoft.AspNetCore.Builder;
using System;
namespace Basket.API.Infrastructure.Middlewares;
namespace Basket.API.Infrastructure.Middlewares
{
public static class FailingMiddlewareAppBuilderExtensions
{
public static IApplicationBuilder UseFailingMiddleware(this IApplicationBuilder builder)
@ -17,4 +14,4 @@ namespace Basket.API.Infrastructure.Middlewares
return builder;
}
}
}

View File

@ -1,15 +1,5 @@
using Basket.API.Infrastructure.ActionResults;
using Basket.API.Infrastructure.Exceptions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Net;
namespace Basket.API.Infrastructure.Filters;
namespace Basket.API.Infrastructure.Filters
{
public partial class HttpGlobalExceptionFilter : IExceptionFilter
{
private readonly IWebHostEnvironment env;
@ -55,4 +45,3 @@ namespace Basket.API.Infrastructure.Filters
context.ExceptionHandled = true;
}
}
}

View File

@ -1,9 +1,9 @@
namespace Basket.API.Infrastructure.Filters
{
namespace Basket.API.Infrastructure.Filters;
public class JsonErrorResponse
{
public string[] Messages { get; set; }
public object DeveloperMessage { get; set; }
}
}

View File

@ -1,9 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Linq;
namespace Basket.API.Infrastructure.Filters;
namespace Basket.API.Infrastructure.Filters
{
public class ValidateModelStateFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
@ -27,4 +23,4 @@ namespace Basket.API.Infrastructure.Filters
context.Result = new BadRequestObjectResult(json);
}
}
}

View File

@ -1,11 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
using System.Linq;
namespace Basket.API.Infrastructure.Filters;
namespace Basket.API.Infrastructure.Filters
{
public class AuthorizeCheckOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
@ -33,4 +27,3 @@ namespace Basket.API.Infrastructure.Filters
};
}
}
}

View File

@ -1,19 +1,13 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace Basket.API.Infrastructure.Middlewares;
namespace Basket.API.Infrastructure.Middlewares
{
public class FailingMiddleware
{
private readonly RequestDelegate _next;
private bool _mustFail;
private readonly FailingOptions _options;
private readonly ILogger _logger;
private readonly Microsoft.Extensions.Logging.ILogger _logger;
public FailingMiddleware(RequestDelegate next, ILogger<FailingMiddleware> logger, FailingOptions options)
public FailingMiddleware(RequestDelegate next, Microsoft.Extensions.Logging.ILogger<FailingMiddleware> logger, FailingOptions options)
{
_next = next;
_options = options;
@ -92,4 +86,3 @@ namespace Basket.API.Infrastructure.Middlewares
|| _options.EndpointPaths.Count == 0);
}
}
}

View File

@ -1,7 +1,5 @@
using System.Collections.Generic;
namespace Basket.API.Infrastructure.Middlewares;
namespace Basket.API.Infrastructure.Middlewares
{
public class FailingOptions
{
public string ConfigPath = "/Failing";
@ -9,4 +7,4 @@ namespace Basket.API.Infrastructure.Middlewares
public List<string> NotFilteredPaths { get; set; } = new List<string>();
}
}

View File

@ -1,9 +1,5 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using System;
namespace Basket.API.Infrastructure.Middlewares;
namespace Basket.API.Infrastructure.Middlewares
{
public class FailingStartupFilter : IStartupFilter
{
private readonly Action<FailingOptions> _options;
@ -21,4 +17,4 @@ namespace Basket.API.Infrastructure.Middlewares
};
}
}
}

View File

@ -1,9 +1,5 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Basket.API.Infrastructure.Middlewares;
namespace Basket.API.Infrastructure.Middlewares
{
public static class WebHostBuildertExtensions
{
public static IWebHostBuilder UseFailing(this IWebHostBuilder builder, Action<FailingOptions> options)
@ -15,4 +11,4 @@ namespace Basket.API.Infrastructure.Middlewares
return builder;
}
}
}

View File

@ -1,13 +1,4 @@
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text.Json;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Repositories
{
namespace Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Repositories;
public class RedisBasketRepository : IBasketRepository
{
private readonly ILogger<RedisBasketRepository> _logger;
@ -70,4 +61,3 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Reposit
return _redis.GetServer(endpoint.First());
}
}
}

View File

@ -1,13 +1,5 @@
using Basket.API.IntegrationEvents.Events;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.Extensions.Logging;
using Serilog.Context;
using System;
using System.Threading.Tasks;
namespace Basket.API.IntegrationEvents.EventHandling;
namespace Basket.API.IntegrationEvents.EventHandling
{
public class OrderStartedIntegrationEventHandler : IIntegrationEventHandler<OrderStartedIntegrationEvent>
{
private readonly IBasketRepository _repository;
@ -31,7 +23,7 @@ namespace Basket.API.IntegrationEvents.EventHandling
}
}
}
}

View File

@ -1,14 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.Extensions.Logging;
using Serilog.Context;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling;
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling
{
public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>
{
private readonly ILogger<ProductPriceChangedIntegrationEventHandler> _logger;
@ -60,5 +51,3 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
}
}
}
}

View File

@ -1,7 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
namespace Basket.API.IntegrationEvents.Events;
namespace Basket.API.IntegrationEvents.Events
{
// Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
@ -12,4 +10,4 @@ namespace Basket.API.IntegrationEvents.Events
public OrderStartedIntegrationEvent(string userId)
=> UserId = userId;
}
}

View File

@ -1,7 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events
{
// Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
@ -20,4 +18,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
OldPrice = oldPrice;
}
}
}

View File

@ -1,9 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using System;
namespace Basket.API.IntegrationEvents.Events;
namespace Basket.API.IntegrationEvents.Events
{
public record UserCheckoutAcceptedIntegrationEvent : IntegrationEvent
{
public string UserId { get; }
@ -61,4 +57,3 @@ namespace Basket.API.IntegrationEvents.Events
}
}
}

View File

@ -1,7 +1,4 @@
using System;
namespace Basket.API.Model
{
namespace Basket.API.Model;
public class BasketCheckout
{
public string City { get; set; }
@ -28,5 +25,3 @@ namespace Basket.API.Model
public Guid RequestId { get; set; }
}
}

View File

@ -1,8 +1,5 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
{
public class BasketItem : IValidatableObject
{
public string Id { get; set; }
@ -24,4 +21,3 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
return results;
}
}
}

View File

@ -1,7 +1,4 @@
using System.Collections.Generic;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
{
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model;
public class CustomerBasket
{
public string BuyerId { get; set; }
@ -18,4 +15,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
BuyerId = customerId;
}
}
}

View File

@ -1,8 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
{
public interface IBasketRepository
{
Task<CustomerBasket> GetBasketAsync(string customerId);
@ -10,4 +7,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
Task<CustomerBasket> UpdateBasketAsync(CustomerBasket basket);
Task<bool> DeleteBasketAsync(string id);
}
}

View File

@ -1,18 +1,4 @@
using Basket.API.Infrastructure.Middlewares;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.eShopOnContainers.Services.Basket.API;
using Microsoft.Extensions.Configuration;
using Azure.Identity;
using Serilog;
using System;
using System.IO;
using System.Net;
using Azure.Core;
var configuration = GetConfiguration();
var configuration = GetConfiguration();
Log.Logger = CreateSerilogLogger(configuration);

View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Basket.API.Services
{
namespace Microsoft.eShopOnContainers.Services.Basket.API.Services;
public interface IIdentityService
{
string GetUserIdentity();
}
}

View File

@ -1,9 +1,5 @@

using Microsoft.AspNetCore.Http;
using System;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Services;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Services
{
public class IdentityService : IIdentityService
{
private IHttpContextAccessor _context;
@ -18,4 +14,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Services
return _context.HttpContext.User.FindFirst("sub").Value;
}
}
}

View File

@ -1,41 +1,5 @@
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Basket.API.Infrastructure.Filters;
using Basket.API.IntegrationEvents.EventHandling;
using Basket.API.IntegrationEvents.Events;
using GrpcBasket;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.ServiceBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.eShopOnContainers.Services.Basket.API.Controllers;
using Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Repositories;
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling;
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using RabbitMQ.Client;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
namespace Microsoft.eShopOnContainers.Services.Basket.API;
namespace Microsoft.eShopOnContainers.Services.Basket.API
{
public class Startup
{
public Startup(IConfiguration configuration)
@ -66,7 +30,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
services.AddSwaggerGen(options =>
{
options.DescribeAllEnumsAsStrings();
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "eShopOnContainers - Basket HTTP API",
@ -360,4 +323,3 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
return services;
}
}
}

View File

@ -1,10 +1,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.eShopOnContainers.Services.Basket.API;
namespace Microsoft.eShopOnContainers.Services.Basket.API
{
internal class TestHttpResponseTrailersFeature : IHttpResponseTrailersFeature
{
public IHeaderDictionary Trailers { get; set; }
}
}