Style: C# 12 Primary constructor

This commit is contained in:
Kamigen
2024-03-30 20:59:17 -04:00
parent 786c65410d
commit 8f58311283
50 changed files with 267 additions and 449 deletions

View File

@@ -11,15 +11,10 @@ public record CreateTodoItemCommand : IRequest<int>
public string? Title { get; init; }
}
public class CreateTodoItemCommandHandler : IRequestHandler<CreateTodoItemCommand, int>
public class CreateTodoItemCommandHandler(
IApplicationDbContext context)
: IRequestHandler<CreateTodoItemCommand, int>
{
private readonly IApplicationDbContext _context;
public CreateTodoItemCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<int> Handle(CreateTodoItemCommand request, CancellationToken cancellationToken)
{
var entity = new TodoItem
@@ -31,9 +26,9 @@ public class CreateTodoItemCommandHandler : IRequestHandler<CreateTodoItemComman
entity.AddDomainEvent(new TodoItemCreatedEvent(entity));
_context.TodoItems.Add(entity);
context.TodoItems.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
await context.SaveChangesAsync(cancellationToken);
return entity.Id;
}