feat: ajustes e refinamentos
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using Shop.Core.Interfaces;
|
||||
|
||||
namespace Shop.Core;
|
||||
|
||||
public abstract class BaseEntity : IEntityKey<Guid>
|
||||
{
|
||||
protected BaseEntity() => Id = Guid.NewGuid();
|
||||
|
||||
public Guid Id { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Shop.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Classe base usada pelas respostas da API.
|
||||
/// </summary>
|
||||
public abstract class BaseResponse
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Shop.Core.Behaviors;
|
||||
|
||||
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse>
|
||||
{
|
||||
private readonly ILogger<LoggingBehavior<TRequest, TResponse>> _logger;
|
||||
|
||||
public LoggingBehavior(ILogger<LoggingBehavior<TRequest, TResponse>> logger) => _logger = logger;
|
||||
|
||||
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
|
||||
{
|
||||
var commandName = request.GetType().Name;
|
||||
|
||||
_logger.LogInformation("----- Handling command {CommandName} ({@Command})", commandName, request);
|
||||
|
||||
var response = await next();
|
||||
|
||||
_logger.LogInformation("----- Command {CommandName} handled - response: {@Response}", commandName, response);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JsonNet.ContractResolvers" Version="2.0.0" />
|
||||
<PackageReference Include="MediatR" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -3,18 +3,25 @@ using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.ResponseCompression;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Shop.Core.Extensions;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal);
|
||||
builder.Services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
|
||||
builder.Services.Configure<KestrelServerOptions>(options => options.AddServerHeader = false);
|
||||
builder.Services.Configure<MvcNewtonsoftJsonOptions>(options => options.SerializerSettings.Configure());
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddResponseCompression(options => options.Providers.Add<GzipCompressionProvider>());
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddControllers().AddNewtonsoftJson();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
@@ -42,10 +49,6 @@ builder.Services.AddSwaggerGen(options =>
|
||||
});
|
||||
builder.Services.AddSwaggerGenNewtonsoftSupport();
|
||||
|
||||
builder.Services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal);
|
||||
builder.Services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
|
||||
builder.Services.Configure<KestrelServerOptions>(options => options.AddServerHeader = false);
|
||||
|
||||
builder.Host.UseDefaultServiceProvider((context, options) =>
|
||||
{
|
||||
options.ValidateScopes = context.HostingEnvironment.IsDevelopment();
|
||||
|
||||
Reference in New Issue
Block a user