Add Exception middleware

This commit is contained in:
2022-09-01 23:02:49 +01:00
parent 2ac5937096
commit dcf3b1020a
14 changed files with 241 additions and 90 deletions

View File

@@ -1,5 +1,6 @@
using AutoMapper;
using Diary.Component.Entries.Repository;
using Diary.Data;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -18,11 +19,13 @@ namespace Diary.Component.Entries.Service
{
private readonly IEntryRepository _entryRepository;
private readonly IMapper _mapper;
private readonly IUnitOfWork _unitOfWork;
public EntryService(IEntryRepository entryRepository, IMapper mapper)
public EntryService(IEntryRepository entryRepository, IMapper mapper, IUnitOfWork unitOfWork)
{
_entryRepository = entryRepository ?? throw new ArgumentNullException(nameof(entryRepository));
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
}
@@ -32,6 +35,8 @@ namespace Diary.Component.Entries.Service
await _entryRepository.CreateAsync(entry);
await _unitOfWork.CompleteAsync();
return _mapper.Map<EntryResource>(entry);
}