Standard-String-Localizer aus Diensten entfernt.

This commit is contained in:
Developer 02 2024-06-13 14:12:09 +02:00
parent cb28ce39a1
commit ee045d5bfd
3 changed files with 9 additions and 18 deletions

View File

@ -27,10 +27,9 @@ namespace DigitalData.Core.Application
/// Initializes a new instance of the BasicCRUDService with the specified repository, translation service, and AutoMapper configuration.
/// </summary>
/// <param name="repository">The CRUD repository for accessing and manipulating entity data.</param>
/// <param name="translationService">The service used for key-based text translations, facilitating localization.</param>
/// <param name="mapper">The AutoMapper instance for mapping between DTOs and entities.</param>
public BasicCRUDService(TCRUDRepository repository, IStringLocalizer defaultLocalizer, IMapper mapper) :
base(repository, defaultLocalizer, mapper)
public BasicCRUDService(TCRUDRepository repository, IMapper mapper) :
base(repository, mapper)
{
}
}

View File

@ -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>

View File

@ -19,9 +19,8 @@ namespace DigitalData.Core.Application
public string SearchRootPath { get; }
private readonly DateTimeOffset _userCacheExpiration;
public Dictionary<string, string> CustomSearchFilters { get; }
protected readonly IStringLocalizer _localizer;
public DirectorySearchService(IConfiguration configuration, ILogger<DirectorySearchService> logger, IMemoryCache memoryCache, IStringLocalizer localizer)
public DirectorySearchService(IConfiguration configuration, ILogger<DirectorySearchService> logger, IMemoryCache memoryCache)
{
_memoryCache = memoryCache;
@ -39,8 +38,6 @@ namespace DigitalData.Core.Application
_userCacheExpiration = default;
else
_userCacheExpiration = DateTimeOffset.Now.Date.AddDays(dayCounts);
_localizer = localizer;
}
public bool ValidateCredentials(string dirEntryUsername, string dirEntryPassword)
@ -85,7 +82,7 @@ namespace DigitalData.Core.Application
_memoryCache.TryGetValue(username, out DirectoryEntry? searchRoot);
if (searchRoot is null)
return Result.Fail<IEnumerable<ResultPropertyCollection>>().Message(_localizer[Key.DirSearcherDisconnected]);
return Result.Fail<IEnumerable<ResultPropertyCollection>>();
return FindAll(searchRoot, filter, searchScope, sizeLimit, properties);
}