Skip to content

Commit

Permalink
chore: bump project to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
EnisMulic committed Apr 13, 2024
1 parent 6f3fe00 commit c3f3d4d
Show file tree
Hide file tree
Showing 29 changed files with 74 additions and 190 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,6 @@ csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion

# Primary constructor
dotnet_diagnostic.IDE0290.severity = none
9 changes: 2 additions & 7 deletions src/Api/Options/MicrosoftEntraSwaggerConfigurationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@

namespace Api.Options;

public class MicrosoftEntraSwaggerConfigurationOptions : IConfigureOptions<SwaggerGenOptions>
public class MicrosoftEntraSwaggerConfigurationOptions(IOptions<MicrosoftEntraOptions> options) : IConfigureOptions<SwaggerGenOptions>
{
private readonly MicrosoftEntraOptions _options;

public MicrosoftEntraSwaggerConfigurationOptions(IOptions<MicrosoftEntraOptions> options)
{
_options = options.Value;
}
private readonly MicrosoftEntraOptions _options = options.Value;

public void Configure(SwaggerGenOptions options)
{
Expand Down
9 changes: 2 additions & 7 deletions src/Api/Services/CurrentUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@

namespace Api.Services;

public class CurrentUserService : ICurrentUserService
public class CurrentUserService(IHttpContextAccessor httpContextAccessor) : ICurrentUserService
{
private readonly IHttpContextAccessor _httpContextAccessor;

public CurrentUserService(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
private readonly IHttpContextAccessor _httpContextAccessor = httpContextAccessor;

public string? Email => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Name);
}
12 changes: 3 additions & 9 deletions src/Application/Common/Behaviours/LoggingBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@

namespace Application.Common.Behaviours
{
public class LoggingBehaviour<TRequest> : IRequestPreProcessor<TRequest> where TRequest : notnull
public class LoggingBehaviour<TRequest>(ILogger<TRequest> logger, ICurrentUserService currentUserService) : IRequestPreProcessor<TRequest> where TRequest : notnull
{
private readonly ILogger<TRequest> _logger;
private readonly ICurrentUserService _currentUserService;

public LoggingBehaviour(ILogger<TRequest> logger, ICurrentUserService currentUserService)
{
_logger = logger;
_currentUserService = currentUserService;
}
private readonly ILogger<TRequest> _logger = logger;
private readonly ICurrentUserService _currentUserService = currentUserService;

public Task Process(TRequest request, CancellationToken cancellationToken)
{
Expand Down
20 changes: 6 additions & 14 deletions src/Application/Common/Behaviours/PerformanceBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@ namespace Application.Common.Behaviours;
/// </summary>
/// <typeparam name="TRequest"></typeparam>
/// <typeparam name="TResponse"></typeparam>
public class PerformanceBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse>
public class PerformanceBehaviour<TRequest, TResponse>(
ILogger<TRequest> logger,
ICurrentUserService currentUserService) : IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse>
{
private readonly Stopwatch _timer;
private readonly ILogger<TRequest> _logger;
private readonly ICurrentUserService _currentUserService;

public PerformanceBehaviour(
ILogger<TRequest> logger,
ICurrentUserService currentUserService)
{
_timer = new Stopwatch();

_logger = logger;
_currentUserService = currentUserService;
}
private readonly Stopwatch _timer = new();
private readonly ILogger<TRequest> _logger = logger;
private readonly ICurrentUserService _currentUserService = currentUserService;

public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
Expand Down
9 changes: 2 additions & 7 deletions src/Application/Common/Behaviours/ValidationBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@

namespace Application.Common.Behaviours;

public class ValidationBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
public class ValidationBehaviour<TRequest, TResponse>(IEnumerable<IValidator<TRequest>> validators) : IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly IEnumerable<IValidator<TRequest>> _validators;

public ValidationBehaviour(IEnumerable<IValidator<TRequest>> validators)
{
_validators = validators;
}
private readonly IEnumerable<IValidator<TRequest>> _validators = validators;

public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Common/Models/OpenApiTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Application.Common.Models;

public static class OpenApiTags
{
public static List<OpenApiTag> TodoList { get; } = new() { new OpenApiTag { Name = "Todo Lists" } };
public static List<OpenApiTag> TodoList { get; } = [new OpenApiTag { Name = "Todo Lists" }];
}
18 changes: 5 additions & 13 deletions src/Application/Common/Models/PaginatedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@

namespace Application.Common.Models;

public class PaginatedList<T>
public class PaginatedList<T>(List<T> items, int count, int pageNumber, int pageSize)
{
public List<T> Items { get; }
public int PageNumber { get; }
public int TotalPages { get; }
public int TotalCount { get; }

public PaginatedList(List<T> items, int count, int pageNumber, int pageSize)
{
PageNumber = pageNumber;
TotalPages = (int)Math.Ceiling(count / (double)pageSize);
TotalCount = count;
Items = items;
}
public List<T> Items { get; } = items;
public int PageNumber { get; } = pageNumber;
public int TotalPages { get; } = (int)Math.Ceiling(count / (double)pageSize);
public int TotalCount { get; } = count;

public bool HasPreviousPage => PageNumber > 1;

Expand Down
2 changes: 1 addition & 1 deletion src/Application/Domain/Entities/TodoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TodoItem : BaseAuditableEntity, IHasDomainEvent, ISoftDelete
public int TodoListId { get; private set; }
public TodoList TodoList { get; private set; } = null!;

public List<DomainEvent> DomainEvents { get; private set; } = new List<DomainEvent>();
public List<DomainEvent> DomainEvents { get; private set; } = [];

private TodoItem() { }

Expand Down
8 changes: 2 additions & 6 deletions src/Application/Domain/Events/TodoItemCompletedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

namespace Application.Domain.Events;

public class TodoItemCompletedEvent : DomainEvent
public class TodoItemCompletedEvent(TodoItem item) : DomainEvent
{
public TodoItem Item { get; }
public TodoItemCompletedEvent(TodoItem item)
{
Item = item;
}
public TodoItem Item { get; } = item;
}
8 changes: 2 additions & 6 deletions src/Application/Domain/Events/TodoItemCreatedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

namespace Application.Domain.Events;

public class TodoItemCreatedEvent : DomainEvent
public class TodoItemCreatedEvent(TodoItem item) : DomainEvent
{
public TodoItem Item { get; }
public TodoItemCreatedEvent(TodoItem item)
{
Item = item;
}
public TodoItem Item { get; } = item;
}
8 changes: 2 additions & 6 deletions src/Application/Domain/Events/TodoItemDeletedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
using Application.Domain.Entities;

namespace Application.Domain.Events;
public class TodoItemDeletedEvent : DomainEvent
public class TodoItemDeletedEvent(TodoItem item) : DomainEvent
{
public TodoItem Item { get; }
public TodoItemDeletedEvent(TodoItem item)
{
Item = item;
}
public TodoItem Item { get; } = item;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
namespace Application.Domain.Exceptions;

public class UnsupportedColourException : Exception
public class UnsupportedColourException(string code) : Exception($"Colour \"{code}\" is unsupported.")
{
public UnsupportedColourException(string code)
: base($"Colour \"{code}\" is unsupported.")
{
}
}
11 changes: 3 additions & 8 deletions src/Application/Features/Todos/CompleteTodoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@ public void AddRoutes(IEndpointRouteBuilder app)

public record CompleteTodoCommand(int Id) : IRequest;

public class CompleteTodoCommandHandler : IRequestHandler<CompleteTodoCommand, Unit>
public class CompleteTodoCommandHandler(ApplicationDbContext context) : IRequestHandler<CompleteTodoCommand, Unit>
{
private readonly ApplicationDbContext _context;

public CompleteTodoCommandHandler(ApplicationDbContext context)
{
_context = context;
}
private readonly ApplicationDbContext _context = context;

public async Task<Unit> Handle(CompleteTodoCommand request, CancellationToken cancellationToken)
{
var item = await _context.TodoItems.FindAsync(new object?[] { request.Id }, cancellationToken: cancellationToken)
var item = await _context.TodoItems.FindAsync([request.Id], cancellationToken: cancellationToken)
?? throw new NotFoundException(nameof(TodoItem), request.Id);

if (!item.Done)
Expand Down
11 changes: 3 additions & 8 deletions src/Application/Features/Todos/CreateTodoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,13 @@ public CreeateTodoItemCommandValidator(IDateTime dateTime)
}
}

public class CreeateTodoItemCommandHandler : IRequestHandler<CreeateTodoItemCommand, int>
public class CreeateTodoItemCommandHandler(ApplicationDbContext context) : IRequestHandler<CreeateTodoItemCommand, int>
{
private readonly ApplicationDbContext _context;

public CreeateTodoItemCommandHandler(ApplicationDbContext context)
{
_context = context;
}
private readonly ApplicationDbContext _context = context;

public async Task<int> Handle(CreeateTodoItemCommand request, CancellationToken cancellationToken)
{
var todoList = await _context.TodoLists.FindAsync(new object?[] { request.Id }, cancellationToken)
var todoList = await _context.TodoLists.FindAsync([request.Id], cancellationToken)
?? throw new NotFoundException(nameof(TodoList), request.Id);

var todoItem = TodoItem.Create(request.Item.Title,
Expand Down
9 changes: 2 additions & 7 deletions src/Application/Features/Todos/CreateTodoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,9 @@ public CreateTodoListCommandValidator()
}
}

public class CreateTodoListCommandHandler : IRequestHandler<CreateTodoListCommand, int>
public class CreateTodoListCommandHandler(ApplicationDbContext context) : IRequestHandler<CreateTodoListCommand, int>
{
private readonly ApplicationDbContext _context;

public CreateTodoListCommandHandler(ApplicationDbContext context)
{
_context = context;
}
private readonly ApplicationDbContext _context = context;

public async Task<int> Handle(CreateTodoListCommand request, CancellationToken cancellationToken)
{
Expand Down
11 changes: 3 additions & 8 deletions src/Application/Features/Todos/DeleteTodoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,13 @@ public void AddRoutes(IEndpointRouteBuilder app)

public record DeleteTodoItemCommand(int Id) : IRequest;

public class DeleteTodoItemCommandHandler : IRequestHandler<DeleteTodoItemCommand, Unit>
public class DeleteTodoItemCommandHandler(ApplicationDbContext context) : IRequestHandler<DeleteTodoItemCommand, Unit>
{
private readonly ApplicationDbContext _context;

public DeleteTodoItemCommandHandler(ApplicationDbContext context)
{
_context = context;
}
private readonly ApplicationDbContext _context = context;

public async Task<Unit> Handle(DeleteTodoItemCommand request, CancellationToken cancellationToken)
{
var item = await _context.TodoItems.FindAsync(new object?[] { request.Id }, cancellationToken: cancellationToken)
var item = await _context.TodoItems.FindAsync([request.Id], cancellationToken: cancellationToken)
?? throw new NotFoundException(nameof(TodoItem), request.Id);

_context.TodoItems.Remove(item);
Expand Down
9 changes: 2 additions & 7 deletions src/Application/Features/Todos/DeleteTodoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,9 @@ public void AddRoutes(IEndpointRouteBuilder app)

public record DeleteTodoListCommand(int Id) : IRequest;

public class DeleteTodoListCommandHandler : IRequestHandler<DeleteTodoListCommand, Unit>
public class DeleteTodoListCommandHandler(ApplicationDbContext context) : IRequestHandler<DeleteTodoListCommand, Unit>
{
private readonly ApplicationDbContext _context;

public DeleteTodoListCommandHandler(ApplicationDbContext context)
{
_context = context;
}
private readonly ApplicationDbContext _context = context;

public async Task<Unit> Handle(DeleteTodoListCommand request, CancellationToken cancellationToken)
{
Expand Down
12 changes: 3 additions & 9 deletions src/Application/Features/Todos/GetTodos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,10 @@ public void AddRoutes(IEndpointRouteBuilder app)

public record GetTodosQuery : IRequest<List<TodoListResponse>>;

public class GetTodosQueryHandler : IRequestHandler<GetTodosQuery, List<TodoListResponse>>
public class GetTodosQueryHandler(ApplicationDbContext context, IMapper mapper) : IRequestHandler<GetTodosQuery, List<TodoListResponse>>
{
private readonly ApplicationDbContext _context;
private readonly IMapper _mapper;

public GetTodosQueryHandler(ApplicationDbContext context, IMapper mapper)
{
_context = context;
_mapper = mapper;
}
private readonly ApplicationDbContext _context = context;
private readonly IMapper _mapper = mapper;

public async Task<List<TodoListResponse>> Handle(GetTodosQuery request, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@

namespace Application.Features.Todos;

public class TodoItemCompletedHandler : INotificationHandler<TodoItemCompletedEvent>
public class TodoItemCompletedHandler(ILogger<TodoItemCompletedHandler> logger) : INotificationHandler<TodoItemCompletedEvent>
{
private readonly ILogger<TodoItemCompletedHandler> _logger;

public TodoItemCompletedHandler(ILogger<TodoItemCompletedHandler> logger)
{
_logger = logger;
}
private readonly ILogger<TodoItemCompletedHandler> _logger = logger;

public Task Handle(TodoItemCompletedEvent notification, CancellationToken cancellationToken)
{
Expand Down
9 changes: 2 additions & 7 deletions src/Application/Features/Todos/TodoItemCreatedEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@

namespace Application.Features.Todos;

public class TodoItemCreatedHandler : INotificationHandler<TodoItemCreatedEvent>
public class TodoItemCreatedHandler(ILogger<TodoItemCreatedHandler> logger) : INotificationHandler<TodoItemCreatedEvent>
{
private readonly ILogger<TodoItemCreatedHandler> _logger;

public TodoItemCreatedHandler(ILogger<TodoItemCreatedHandler> logger)
{
_logger = logger;
}
private readonly ILogger<TodoItemCreatedHandler> _logger = logger;

public Task Handle(TodoItemCreatedEvent notification, CancellationToken cancellationToken)
{
Expand Down
9 changes: 2 additions & 7 deletions src/Application/Features/Todos/TodoItemDeletedEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@

namespace Application.Features.Todos;

public class TodoItemDeletedHandler : INotificationHandler<TodoItemDeletedEvent>
public class TodoItemDeletedHandler(ILogger<TodoItemDeletedHandler> logger) : INotificationHandler<TodoItemDeletedEvent>
{
private readonly ILogger<TodoItemDeletedHandler> _logger;

public TodoItemDeletedHandler(ILogger<TodoItemDeletedHandler> logger)
{
_logger = logger;
}
private readonly ILogger<TodoItemDeletedHandler> _logger = logger;

public Task Handle(TodoItemDeletedEvent notification, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

namespace Application.Infrastructure.Persistance;

public class ApplicationDbContext : DbContext
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : DbContext(options)
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}

public DbSet<TodoList> TodoLists => Set<TodoList>();
public DbSet<TodoItem> TodoItems => Set<TodoItem>();

Expand Down
Loading

0 comments on commit c3f3d4d

Please sign in to comment.