Standard-String-Localizer aus Diensten entfernt.
This commit is contained in:
@@ -3,7 +3,6 @@ using DigitalData.Core.Contracts.Infrastructure;
|
||||
using AutoMapper;
|
||||
using System.Reflection;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using DigitalData.Core.DTO;
|
||||
|
||||
namespace DigitalData.Core.Application
|
||||
@@ -22,23 +21,19 @@ namespace DigitalData.Core.Application
|
||||
protected readonly TCRUDRepository _repository;
|
||||
protected readonly IMapper _mapper;
|
||||
protected readonly PropertyInfo? _keyPropertyInfo;
|
||||
protected readonly IStringLocalizer _localizer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the CRUDService class with the specified repository, translation service, and mapper.
|
||||
/// </summary>
|
||||
/// <param name="repository">The CRUD repository for accessing the database.</param>
|
||||
/// <param name="localizer">The localizer for translating messages based on culture.</param>
|
||||
/// <param name="mapper">The AutoMapper instance for mapping between DTOs and entity objects.</param>
|
||||
public CRUDService(TCRUDRepository repository, IStringLocalizer localizer, IMapper mapper)
|
||||
public CRUDService(TCRUDRepository repository, IMapper mapper)
|
||||
{
|
||||
_repository = repository;
|
||||
_mapper = mapper;
|
||||
|
||||
_keyPropertyInfo = typeof(TEntity).GetProperties()
|
||||
.FirstOrDefault(prop => Attribute.IsDefined(prop, typeof(KeyAttribute)));
|
||||
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -62,7 +57,7 @@ namespace DigitalData.Core.Application
|
||||
{
|
||||
var entity = await _repository.ReadByIdAsync(id);
|
||||
return entity is null
|
||||
? Result.Fail<TReadDto>().Message(_localizer[Key.EntityDoesNotExist])
|
||||
? Result.Fail<TReadDto>()
|
||||
: Result.Success(_mapper.MapOrThrow<TReadDto>(entity));
|
||||
}
|
||||
|
||||
@@ -86,7 +81,7 @@ namespace DigitalData.Core.Application
|
||||
{
|
||||
var entity = _mapper.MapOrThrow<TEntity>(updateDto);
|
||||
bool isUpdated = await _repository.UpdateAsync(entity);
|
||||
return isUpdated ? Result.Success() : Result.Fail().Message(_localizer[Key.UpdateFailed]);
|
||||
return isUpdated ? Result.Success() : Result.Fail();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,10 +94,10 @@ namespace DigitalData.Core.Application
|
||||
TEntity? entity = await _repository.ReadByIdAsync(id);
|
||||
|
||||
if (entity is null)
|
||||
return Result.Fail().Message(_localizer[Key.DeletionFailed], _localizer[Key.EntityDoesNotExist]);
|
||||
return Result.Fail();
|
||||
|
||||
bool isDeleted = await _repository.DeleteAsync(entity);
|
||||
return isDeleted ? Result.Success() : Result.Fail().Message(_localizer[Key.DeletionFailed]);
|
||||
return isDeleted ? Result.Success() : Result.Fail();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user