Erweiterung der DTOs und Implementierung der Lokalisierungsdienste
- Neue DTO-Extension-Methoden hinzugefügt, um die Verarbeitung und Zuweisung von Nachrichten und Benachrichtigungen in Ergebnisobjekten zu vereinfachen. - Lokalisierungsunterstützung in der API-Schicht implementiert, einschließlich Cookie-basierter Lokalisierung und Konfiguration unterstützter Kulturen. - Die Integration von StringLocalizer in die API-Schicht wurde durchgeführt, um eine nahtlose Mehrsprachigkeit zu ermöglichen. - Fehlerbehandlung für fehlende Konfigurationseinstellungen verbessert. Die Änderungen verbessern die Flexibilität und Wartbarkeit des Codes und unterstützen eine effizientere Internationalisierung der Anwendung.
This commit is contained in:
22
DigitalData.Core.DTO/AutoMapperExtension.cs
Normal file
22
DigitalData.Core.DTO/AutoMapperExtension.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace DigitalData.Core.DTO
|
||||
{
|
||||
public static class AutoMapperExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps a source object to a destination object, or throws an exception if the mapping result is null.
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource">The source object type.</typeparam>
|
||||
/// <typeparam name="TDestination">The destination object type.</typeparam>
|
||||
/// <param name="source">The source object to map from.</param>
|
||||
/// <returns>The mapped destination object.</returns>
|
||||
/// <exception cref="MappingResultNullException">Thrown when the mapping result is null.</exception>
|
||||
public static TDestination MapOrThrow<TDestination>(this IMapper mapper, object source)
|
||||
{
|
||||
return mapper.Map<TDestination>(source) ?? throw new AutoMapperMappingException(
|
||||
$"Mapping to {typeof(TDestination).FullName} resulted in a null object. " +
|
||||
"Hint: Ensure that the AutoMapper profile configuration for this mapping is correct.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user