Standard-String-Localizer aus Diensten entfernt.
This commit is contained in:
parent
cb28ce39a1
commit
ee045d5bfd
@ -27,10 +27,9 @@ namespace DigitalData.Core.Application
|
|||||||
/// Initializes a new instance of the BasicCRUDService with the specified repository, translation service, and AutoMapper configuration.
|
/// Initializes a new instance of the BasicCRUDService with the specified repository, translation service, and AutoMapper configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repository">The CRUD repository for accessing and manipulating entity data.</param>
|
/// <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>
|
/// <param name="mapper">The AutoMapper instance for mapping between DTOs and entities.</param>
|
||||||
public BasicCRUDService(TCRUDRepository repository, IStringLocalizer defaultLocalizer, IMapper mapper) :
|
public BasicCRUDService(TCRUDRepository repository, IMapper mapper) :
|
||||||
base(repository, defaultLocalizer, mapper)
|
base(repository, mapper)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@ using DigitalData.Core.Contracts.Infrastructure;
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Microsoft.Extensions.Localization;
|
|
||||||
using DigitalData.Core.DTO;
|
using DigitalData.Core.DTO;
|
||||||
|
|
||||||
namespace DigitalData.Core.Application
|
namespace DigitalData.Core.Application
|
||||||
@ -22,23 +21,19 @@ namespace DigitalData.Core.Application
|
|||||||
protected readonly TCRUDRepository _repository;
|
protected readonly TCRUDRepository _repository;
|
||||||
protected readonly IMapper _mapper;
|
protected readonly IMapper _mapper;
|
||||||
protected readonly PropertyInfo? _keyPropertyInfo;
|
protected readonly PropertyInfo? _keyPropertyInfo;
|
||||||
protected readonly IStringLocalizer _localizer;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the CRUDService class with the specified repository, translation service, and mapper.
|
/// Initializes a new instance of the CRUDService class with the specified repository, translation service, and mapper.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repository">The CRUD repository for accessing the database.</param>
|
/// <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>
|
/// <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;
|
_repository = repository;
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
|
|
||||||
_keyPropertyInfo = typeof(TEntity).GetProperties()
|
_keyPropertyInfo = typeof(TEntity).GetProperties()
|
||||||
.FirstOrDefault(prop => Attribute.IsDefined(prop, typeof(KeyAttribute)));
|
.FirstOrDefault(prop => Attribute.IsDefined(prop, typeof(KeyAttribute)));
|
||||||
|
|
||||||
_localizer = localizer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -62,7 +57,7 @@ namespace DigitalData.Core.Application
|
|||||||
{
|
{
|
||||||
var entity = await _repository.ReadByIdAsync(id);
|
var entity = await _repository.ReadByIdAsync(id);
|
||||||
return entity is null
|
return entity is null
|
||||||
? Result.Fail<TReadDto>().Message(_localizer[Key.EntityDoesNotExist])
|
? Result.Fail<TReadDto>()
|
||||||
: Result.Success(_mapper.MapOrThrow<TReadDto>(entity));
|
: Result.Success(_mapper.MapOrThrow<TReadDto>(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +81,7 @@ namespace DigitalData.Core.Application
|
|||||||
{
|
{
|
||||||
var entity = _mapper.MapOrThrow<TEntity>(updateDto);
|
var entity = _mapper.MapOrThrow<TEntity>(updateDto);
|
||||||
bool isUpdated = await _repository.UpdateAsync(entity);
|
bool isUpdated = await _repository.UpdateAsync(entity);
|
||||||
return isUpdated ? Result.Success() : Result.Fail().Message(_localizer[Key.UpdateFailed]);
|
return isUpdated ? Result.Success() : Result.Fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -99,10 +94,10 @@ namespace DigitalData.Core.Application
|
|||||||
TEntity? entity = await _repository.ReadByIdAsync(id);
|
TEntity? entity = await _repository.ReadByIdAsync(id);
|
||||||
|
|
||||||
if (entity is null)
|
if (entity is null)
|
||||||
return Result.Fail().Message(_localizer[Key.DeletionFailed], _localizer[Key.EntityDoesNotExist]);
|
return Result.Fail();
|
||||||
|
|
||||||
bool isDeleted = await _repository.DeleteAsync(entity);
|
bool isDeleted = await _repository.DeleteAsync(entity);
|
||||||
return isDeleted ? Result.Success() : Result.Fail().Message(_localizer[Key.DeletionFailed]);
|
return isDeleted ? Result.Success() : Result.Fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -19,9 +19,8 @@ namespace DigitalData.Core.Application
|
|||||||
public string SearchRootPath { get; }
|
public string SearchRootPath { get; }
|
||||||
private readonly DateTimeOffset _userCacheExpiration;
|
private readonly DateTimeOffset _userCacheExpiration;
|
||||||
public Dictionary<string, string> CustomSearchFilters { get; }
|
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;
|
_memoryCache = memoryCache;
|
||||||
|
|
||||||
@ -39,8 +38,6 @@ namespace DigitalData.Core.Application
|
|||||||
_userCacheExpiration = default;
|
_userCacheExpiration = default;
|
||||||
else
|
else
|
||||||
_userCacheExpiration = DateTimeOffset.Now.Date.AddDays(dayCounts);
|
_userCacheExpiration = DateTimeOffset.Now.Date.AddDays(dayCounts);
|
||||||
|
|
||||||
_localizer = localizer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ValidateCredentials(string dirEntryUsername, string dirEntryPassword)
|
public bool ValidateCredentials(string dirEntryUsername, string dirEntryPassword)
|
||||||
@ -85,7 +82,7 @@ namespace DigitalData.Core.Application
|
|||||||
_memoryCache.TryGetValue(username, out DirectoryEntry? searchRoot);
|
_memoryCache.TryGetValue(username, out DirectoryEntry? searchRoot);
|
||||||
|
|
||||||
if (searchRoot is null)
|
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);
|
return FindAll(searchRoot, filter, searchScope, sizeLimit, properties);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user