feat(Application.Abstraction): Erstellt, um Schnittstellen von Core.Application zu behandeln

This commit is contained in:
Developer 02
2025-05-20 16:30:31 +02:00
parent 01025ff36f
commit a0696c5e22
35 changed files with 94 additions and 45 deletions

View File

@@ -1,6 +1,6 @@
using AutoMapper;
using DigitalData.Core.Application.Interfaces;
using DigitalData.Core.Application.Interfaces.Repository;
using DigitalData.Core.Application.Abstraction;
using DigitalData.Core.Application.Abstraction.Repository;
namespace DigitalData.Core.Application
{

View File

@@ -1,8 +1,8 @@
using AutoMapper;
using Microsoft.Extensions.Logging;
using DigitalData.Core.Application.Interfaces.Repository;
using DigitalData.Core.Application.Interfaces;
using DigitalData.Core.Application.DTO;
using DigitalData.Core.Application.Abstraction.DTO;
using DigitalData.Core.Application.Abstraction.Repository;
using DigitalData.Core.Application.Abstraction;
namespace DigitalData.Core.Application
{

View File

@@ -1,4 +1,4 @@
using DigitalData.Core.Application.Interfaces;
using DigitalData.Core.Application.Abstraction;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

View File

@@ -1,17 +0,0 @@
namespace DigitalData.Core.Application.DTO
{
/// <summary>
/// Represents a base Data Transfer Object (DTO) with an identifier.
/// </summary>
/// <typeparam name="TId">The type of the identifier.</typeparam>
/// <param name="Id">The identifier of the DTO.</param>
public record BaseDTO<TId>(TId Id) where TId : notnull
{
/// <summary>
/// Returns the hash code for this instance, based on the identifier.
/// This override ensures that the hash code is derived consistently from the identifier.
/// </summary>
/// <returns>A hash code for the current object, derived from the identifier.</returns>
public override int GetHashCode() => Id.GetHashCode();
}
}

View File

@@ -1,74 +0,0 @@
namespace DigitalData.Core.Application.DTO
{
/// <summary>
/// Represents settings related to user cookie consent dialogs. Designed to be serialized into JSON format for use with JavaScript frontend libraries,
/// such as the bootstrap-cookie-consent-settings at the GitHub repository: https://github.com/shaack/bootstrap-cookie-consent-settings
/// </summary>
public class CookieConsentSettings
{
/// <summary>
/// URL to the privacy policy page.
/// </summary>
public string? PrivacyPolicyUrl { get; set; }
/// <summary>
/// URL to the legal notice page.
/// </summary>
public string? LegalNoticeUrl { get; set; }
/// <summary>
/// URL to the content of the dialog box.
/// </summary>
public string? ContentURL { get; set; }
/// <summary>
/// CSS class for the 'Agree' button.
/// </summary>
public string? ButtonAgreeClass { get; set; }
/// <summary>
/// CSS class for the 'Don't Agree' button.
/// </summary>
public string? ButtonDontAgreeClass { get; set; }
/// <summary>
/// CSS class for the 'Save' button.
/// </summary>
public string? ButtonSaveClass { get; set; }
/// <summary>
/// Language in which the modal is displayed.
/// </summary>
public string? Lang { get; set; }
/// <summary>
/// Default language for the modal if the user's browser language is not supported.
/// </summary>
public string? DefaultLang { get; set; }
/// <summary>
/// Name of the cookie used to store the consent status.
/// </summary>
public string? CookieName { get; set; }
/// <summary>
/// Number of days the cookie will be stored.
/// </summary>
public int CookieStorageDays { get; set; }
/// <summary>
/// Identifier for the modal dialog element.
/// </summary>
public string? ModalId { get; set; }
/// <summary>
/// Indicates whether to also store the settings in the browser's localStorage.
/// </summary>
public bool AlsoUseLocalStorage { get; set; }
/// <summary>
/// List of categories for cookie consent.
/// </summary>
public List<string>? Categories { get; set; }
}
}

View File

@@ -1,33 +0,0 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Configuration;
namespace DigitalData.Core.Application.DTO
{
/// <summary>
/// Provides extension methods for dependency injection.
/// </summary>
public static class DIExtensions
{
/// <summary>
/// Adds the <see cref="CookieConsentSettings"/> to the service collection.
/// </summary>
/// <param name="services">The service collection to add the settings to.</param>
/// <returns>The updated service collection.</returns>
/// <exception cref="ConfigurationErrorsException">
/// Thrown if the 'CookieConsentSettings' section is missing or improperly configured in appsettings.json.
/// </exception>
public static IServiceCollection AddCookieConsentSettings(this IServiceCollection services)
{
services.AddSingleton(sp =>
{
var configuration = sp.GetRequiredService<IConfiguration>();
var settings = configuration.GetSection("CookieConsentSettings").Get<CookieConsentSettings>();
return settings is null
? throw new ConfigurationErrorsException("The 'CookieConsentSettings' section is missing or improperly configured in appsettings.json.")
: settings;
});
return services;
}
}
}

View File

@@ -1,367 +0,0 @@
using Microsoft.Extensions.Logging;
using System.Text;
namespace DigitalData.Core.Application.DTO
{
/// <summary>
/// Provides extension methods for data transfer objects (DTOs).
/// </summary>
public static class DTOExtensions
{
/// <summary>
/// Adds a single message to the result, if not null.
/// </summary>
/// <typeparam name="T">The type of the result.</typeparam>
/// <param name="result">The result to add the message to.</param>
/// <param name="message">The message to add.</param>
/// <returns>The updated result.</returns>
public static T Message<T>(this T result, string? message) where T : Result
{
if(message is not null)
result.Messages.Add(message);
return result;
}
internal static IEnumerable<T> FilterNull<T>(this IEnumerable<T?> list)
{
foreach (var item in list)
if(item is not null)
yield return item;
}
/// <summary>
/// Adds multiple messages to the result, after removing nulls.
/// </summary>
/// <typeparam name="T">The type of the result.</typeparam>
/// <param name="result">The result to add the messages to.</param>
/// <param name="messages">The messages to add.</param>
/// <returns>The updated result.</returns>
public static T Message<T>(this T result, params string?[] messages) where T : Result
{
result.Messages.AddRange(messages.FilterNull());
return result;
}
/// <summary>
/// Adds a collection of messages to the result.
/// </summary>
/// <typeparam name="T">The type of the result.</typeparam>
/// <param name="result">The result to add the messages to.</param>
/// <param name="messages">The collection of messages to add.</param>
/// <returns>The updated result.</returns>
public static T Message<T>(this T result, IEnumerable<string?> messages) where T : Result
{
result.Messages.AddRange(messages.FilterNull());
return result;
}
/// <summary>
/// Adds a notice to the result.
/// </summary>
/// <typeparam name="T">The type of the result.</typeparam>
/// <param name="result">The result to add the notice to.</param>
/// <param name="notice">The notice to add.</param>
/// <returns>The updated result.</returns>
public static T Notice<T>(this T result, Notice notice) where T : Result
{
result.Notices.Add(notice);
return result;
}
/// <summary>
/// Adds a collection of notices to the result.
/// </summary>
/// <typeparam name="T">The type of the result.</typeparam>
/// <param name="result">The result to add the notices to.</param>
/// <param name="notices">The collection of notices to add.</param>
/// <returns>The updated result.</returns>
public static T Notice<T>(this T result, IEnumerable<Notice> notices) where T : Result
{
result.Notices.AddRange(notices);
return result;
}
/// <summary>
/// Adds notices with a specific log level and flags to the result.
/// </summary>
/// <typeparam name="T">The type of the result.</typeparam>
/// <param name="result">The result to add the notices to.</param>
/// <param name="level">The log level of the notices.</param>
/// <param name="flags">The flags associated with the notices.</param>
/// <returns>The updated result.</returns>
public static T Notice<T>(this T result, LogLevel level, params Enum[] flags) where T : Result
{
var notices = flags.Select(flag => new Notice()
{
Flag = flag,
Level = level
});
result.Notices.AddRange(notices);
return result;
}
/// <summary>
/// Adds a notice with a specific log level, flag, and messages to the result.
/// </summary>
/// <typeparam name="T">The type of the result.</typeparam>
/// <param name="result">The result to add the notice to.</param>
/// <param name="level">The log level of the notice.</param>
/// <param name="flag">The flag associated with the notice.</param>
/// <param name="messages">The messages to add to the notice.</param>
/// <returns>The updated result.</returns>
public static T Notice<T>(this T result, LogLevel level, Enum flag, params string?[] messages) where T : Result
{
result.Notices.Add(new Notice()
{
Flag = flag,
Level = level,
Messages = messages.FilterNull().ToList()
});
return result;
}
/// <summary>
/// Adds a notice with a specific log level and messages to the result.
/// </summary>
/// <typeparam name="T">The type of the result.</typeparam>
/// <param name="result">The result to add the notice to.</param>
/// <param name="level">The log level of the notice.</param>
/// <param name="messages">The messages to add to the notice.</param>
/// <returns>The updated result.</returns>
public static T Notice<T>(this T result, LogLevel level, params string[] messages) where T : Result
{
result.Notices.Add(new Notice()
{
Flag = null,
Level = level,
Messages = messages.FilterNull().ToList()
});
return result;
}
/// <summary>
/// Checks if any notice has the specified flag.
/// </summary>
/// <param name="notices">The collection of notices to check.</param>
/// <param name="flag">The flag to check for.</param>
/// <returns>True if any notice has the specified flag; otherwise, false.</returns>
public static bool HasFlag(this IEnumerable<Notice> notices, Enum flag) => notices.Any(n => n.Flag?.ToString() == flag.ToString());
/// <summary>
/// Checks if any notice has any of the specified flags.
/// </summary>
/// <param name="notices">The collection of notices to check.</param>
/// <param name="flags">The flags to check for.</param>
/// <returns>True if any notice has any of the specified flags; otherwise, false.</returns>
public static bool HasAnyFlag(this IEnumerable<Notice> notices, params Enum[] flags) => flags.Any(f => notices.HasFlag(f));
/// <summary>
/// Executes a function based on the success or failure of the task result,
/// without using result data.
/// </summary>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="tResult">The task returning a result to evaluate.</param>
/// <param name="Success">The function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static I? Then<I>(this Result result, Func<I> Success)
{
return result.IsSuccess ? Success() : default;
}
/// <summary>
/// Executes a function based on the success or failure of the task result,
/// using the data in the result.
/// </summary>
/// <typeparam name="T">The type of the data in the result.</typeparam>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="tResult">The task returning a data result to evaluate.</param>
/// <param name="Success">The function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static async Task<I?> ThenAsync<I>(this Result result, Func<Task<I>> SuccessAsync)
{
return result.IsSuccess ? await SuccessAsync() : default;
}
/// <summary>
/// Executes a function based on the success or failure of the result.
/// </summary>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="result">The result to evaluate.</param>
/// <param name="Success">The function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static I Then<I>(this Result result, Func<I> Success, Func<List<string>, List<Notice>, I> Fail)
{
return result.IsSuccess ? Success() : Fail(result.Messages, result.Notices);
}
/// <summary>
/// Asynchronously executes a function based on the success or failure of the result.
/// </summary>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="result">The result to evaluate.</param>
/// <param name="SuccessAsync">The asynchronous function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static async Task<I> ThenAsync<I>(this Result result, Func<Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail)
{
return result.IsSuccess ? await SuccessAsync() : Fail(result.Messages, result.Notices);
}
/// <summary>
/// Executes a function based on the success or failure of the data result.
/// </summary>
/// <typeparam name="T">The type of the data in the result.</typeparam>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="result">The data result to evaluate.</param>
/// <param name="Success">The function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static I Then<T, I>(this DataResult<T> result, Func<T, I> Success, Func<List<string>, List<Notice>, I> Fail)
{
return result.IsSuccess ? Success(result.Data) : Fail(result.Messages, result.Notices);
}
/// <summary>
/// Asynchronously executes a function based on the success or failure of the data result.
/// </summary>
/// <typeparam name="T">The type of the data in the result.</typeparam>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="result">The data result to evaluate.</param>
/// <param name="SuccessAsync">The asynchronous function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static async Task<I> ThenAsync<T, I>(this DataResult<T> result, Func<T, Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail)
{
return result.IsSuccess ? await SuccessAsync(result.Data) : Fail(result.Messages, result.Notices);
}
/// <summary>
/// Asynchronously executes a function based on the success or failure of a task returning a result.
/// </summary>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="tResult">The task returning a result to evaluate.</param>
/// <param name="Success">The function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static async Task<I> ThenAsync<I>(this Task<Result> tResult, Func<I> Success, Func<List<string>, List<Notice>, I> Fail)
{
Result result = await tResult;
return result.IsSuccess ? Success() : Fail(result.Messages, result.Notices);
}
/// <summary>
/// Asynchronously executes a function based on the success or failure of a task returning a result.
/// </summary>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="tResult">The task returning a result to evaluate.</param>
/// <param name="SuccessAsync">The asynchronous function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static async Task<I> ThenAsync<I>(this Task<Result> tResult, Func<Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail)
{
Result result = await tResult;
return result.IsSuccess ? await SuccessAsync() : Fail(result.Messages, result.Notices);
}
/// <summary>
/// Asynchronously executes a function based on the success or failure of a task returning a data result.
/// </summary>
/// <typeparam name="T">The type of the data in the result.</typeparam>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="tResult">The task returning a data result to evaluate.</param>
/// <param name="Success">The function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static async Task<I> ThenAsync<T, I>(this Task<DataResult<T>> tResult, Func<T, I> Success, Func<List<string>, List<Notice>, I> Fail)
{
DataResult<T> result = await tResult;
return result.IsSuccess ? Success(result.Data) : Fail(result.Messages, result.Notices);
}
/// <summary>
/// Asynchronously executes a function based on the success or failure of a task returning a data result.
/// </summary>
/// <typeparam name="T">The type of the data in the result.</typeparam>
/// <typeparam name="I">The type of the return value.</typeparam>
/// <param name="tResult">The task returning a data result to evaluate.</param>
/// <param name="SuccessAsync">The asynchronous function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns>
public static async Task<I> ThenAsync<T, I>(this Task<DataResult<T>> tResult, Func<T, Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail)
{
DataResult<T> result = await tResult;
return result.IsSuccess ? await SuccessAsync(result.Data) : Fail(result.Messages, result.Notices);
}
/// <summary>
/// Joins the values into a single string with optional start, separator, and end strings.
/// </summary>
/// <typeparam name="T">The type of the values.</typeparam>
/// <param name="values">The values to join.</param>
/// <param name="start">The starting string.</param>
/// <param name="separator">The separator string.</param>
/// <param name="end">The ending string.</param>
/// <returns>The joined string.</returns>
public static string Join<T>(this IEnumerable<T> values, string start = "", string seperator = ". ", string end = ".")
=> new StringBuilder(start).Append(string.Join(seperator, values)).Append(end).ToString();
/// <summary>
/// Logs the notices using the specified logger.
/// </summary>
/// <param name="logger">The logger to use.</param>
/// <param name="notices">The collection of notices to log.</param>
/// <param name="start">The starting string for each notice.</param>
/// <param name="separator">The separator string for messages in each notice.</param>
/// <param name="end">The ending string for each notice.</param>
public static void LogNotice(this ILogger logger, IEnumerable<Notice> notices, string start = ": ", string seperator = ". ", string end = ".\n")
{
foreach(LogLevel level in Enum.GetValues(typeof(LogLevel)))
{
var logNotices = notices.Where(n => n.Level == level);
if (!logNotices.Any())
continue;
var sb = new StringBuilder();
foreach(Notice notice in logNotices)
{
if (notice.Flag is not null)
sb.Append(notice.Flag);
if (notice.Messages.Any())
sb.Append(start).Append(string.Join(seperator, notice.Messages)).AppendLine(end);
else sb.Append(end);
}
logger.Log(level, sb.ToString());
}
}
/// <summary>
/// Logs the notices from a result using the specified logger.
/// </summary>
/// <param name="logger">The logger to use.</param>
/// <param name="result">The result containing the notices to log.</param>
/// <param name="start">The starting string for each notice.</param>
/// <param name="separator">The separator string for messages in each notice.</param>
/// <param name="end">The ending string for each notice.</param>
public static void LogNotice(this ILogger logger, Result result, string start = ": ", string seperator = ". ", string end = ".\n")
=> logger.LogNotice(notices: result.Notices, start: start, seperator: seperator, end: end);
/// <summary>
/// Determines if the data result is right (true).
/// </summary>
/// <param name="bResult">The data result to evaluate.</param>
/// <returns>True if the data result is true; otherwise, false.</returns>
public static bool IsRight(this DataResult<bool> bResult) => bResult.Data;
/// <summary>
/// Determines if the data result is wrong (false).
/// </summary>
/// <param name="bResult">The data result to evaluate.</param>
/// <returns>True if the data result is false; otherwise, false.</returns>
public static bool IsWrong(this DataResult<bool> bResult) => !bResult.Data;
}
}

View File

@@ -1,26 +0,0 @@
using System.Text.Json.Serialization;
namespace DigitalData.Core.Application.DTO
{
/// <summary>
/// Represents a result of an operation that includes data, inheriting from <see cref="Result"/>.
/// </summary>
/// <typeparam name="T">The type of the data included in the result.</typeparam>
public class DataResult<T> : Result
{
/// <summary>
/// Gets or sets the data included in the result. This property is required.
/// It will be ignored during JSON serialization if the value is null.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public required T Data { get; set; }
/// <summary>
/// Converts the current <see cref="DataResult{T}"/> to a failed <see cref="DataResult{I}"/>,
/// preserving the messages and notices.
/// </summary>
/// <typeparam name="I">The type of the data in the new failed result.</typeparam>
/// <returns>A failed <see cref="DataResult{I}"/> with the current messages and notices.</returns>
public DataResult<I> ToFail<I>() => Fail<I>().Message(Messages).Notice(Notices);
}
}

View File

@@ -1,50 +0,0 @@
namespace DigitalData.Core.Application.DTO
{
/// <summary>
/// Defines flags that indicate specific types of status or conditions in a service operation.
/// These flags help in categorizing and identifying specific circumstances or issues that may arise during execution.
/// </summary>
public enum Flag
{
/// <summary>
/// Indicates a security breach or vulnerability has been detected during the service operation.
/// </summary>
SecurityBreach,
/// <summary>
/// Indicates a potential issue with data integrity during the service operation.
/// This flag is used when data may have been altered, corrupted, or is otherwise unreliable,
/// which could impact the accuracy or trustworthiness of the operation's results.
/// </summary>
DataIntegrityIssue,
/// <summary>
/// Indicates that either a security breach, a data integrity issue, or both have been detected during the service operation.
/// This flag is used when it is not sure whether the problem is security or data integrity. In this case, data integrity should be checked first.
/// </summary>
SecurityBreachOrDataIntegrity,
/// <summary>
/// Indicates a possible security breach during the service operation.
/// </summary>
PossibleSecurityBreach,
/// <summary>
/// Indicates a possible issue with data integrity during the service operation.
/// This flag is used when there is a suspicion of data alteration, corruption, or unreliability.
/// </summary>
PossibleDataIntegrityIssue,
/// <summary>
/// Indicates that either a possible security breach, a possible data integrity issue, or both have been detected during the service operation.
/// This flag is used when it is uncertain whether the issue is related to security, data integrity, or both.
/// </summary>
PossibleSecurityBreachOrDataIntegrity,
/// <summary>
/// Indicates that the requested resource or operation could not be found.
/// This flag is used when the specified item or condition does not exist or is unavailable.
/// </summary>
NotFound
}
}

View File

@@ -1,25 +0,0 @@
using Microsoft.Extensions.Logging;
namespace DigitalData.Core.Application.DTO
{
/// <summary>
/// Represents a notice for logging purposes, containing a flag, log level, and associated messages.
/// </summary>
public class Notice
{
/// <summary>
/// Gets or sets an optional flag associated with the notice.
/// </summary>
public Enum? Flag { get; init; } = null;
/// <summary>
/// Gets or sets the log level for the notice.
/// </summary>
public LogLevel Level { get; init; } = LogLevel.None;
/// <summary>
/// Gets a list of messages associated with the notice.
/// </summary>
public List<string> Messages { get; init; } = new();
}
}

View File

@@ -1,97 +0,0 @@
using System.Text.Json.Serialization;
namespace DigitalData.Core.Application.DTO
{
/// <summary>
/// Represents the result of an operation, containing information about its success or failure,
/// messages for the client, and notices for logging.
/// </summary>
public class Result
{
/// <summary>
/// Gets or sets a value indicating whether the operation was successful.
/// </summary>
public bool IsSuccess { get; set; } = false;
/// <summary>
/// Gets a value indicating whether the operation failed.
/// </summary>
public bool IsFailed => !IsSuccess;
/// <summary>
/// Gets a list of messages intended for the client.
/// </summary>
public List<string> Messages { get; init; } = new();
/// <summary>
/// Gets a list of notices intended for logging purposes. This property is ignored during JSON serialization.
/// </summary>
[JsonIgnore]
public List<Notice> Notices = new();
/// <summary>
/// Creates a <see cref="DataResult{T}"/> with the specified data.
/// </summary>
/// <typeparam name="T">The type of the data.</typeparam>
/// <param name="data">The data to include in the result.</param>
/// <returns>A new <see cref="DataResult{T}"/> instance.</returns>
public DataResult<T> Data<T>(T data) => new()
{
IsSuccess = IsSuccess,
Messages = Messages,
Notices = Notices,
Data = data
};
/// <summary>
/// Checks if any notice has the specified flag.
/// </summary>
/// <param name="flag">The flag to check.</param>
/// <returns>True if any notice has the specified flag; otherwise, false.</returns>
public bool HasFlag(Enum flag) => Notices.Any(n => n.Flag?.ToString() == flag.ToString());
/// <summary>
/// Checks if any notice has any of the specified flags.
/// </summary>
/// <param name="flags">The flags to check.</param>
/// <returns>True if any notice has any of the specified flags; otherwise, false.</returns>
public bool HasAnyFlag(params Enum[] flags) => flags.Any(HasFlag);
/// <summary>
/// Creates a new successful <see cref="Result"/>.
/// </summary>
/// <returns>A new successful <see cref="Result"/>.</returns>
public static Result Success() => new() { IsSuccess = true };
/// <summary>
/// Creates a new failed <see cref="Result"/>.
/// </summary>
/// <returns>A new failed <see cref="Result"/>.</returns>
public static Result Fail() => new() { IsSuccess = false };
/// <summary>
/// Creates a new successful <see cref="DataResult{T}"/> with the specified data.
/// </summary>
/// <typeparam name="T">The type of the data.</typeparam>
/// <param name="data">The data to include in the result.</param>
/// <returns>A new successful <see cref="DataResult{T}"/> with the specified data.</returns>
public static DataResult<T> Success<T>(T data) => new()
{
IsSuccess = true,
Data = data
};
/// <summary>
/// Creates a new failed <see cref="DataResult{T}"/> with no data.
/// </summary>
/// <typeparam name="T">The type of the data.</typeparam>
/// <returns>A new failed <see cref="DataResult{T}"/> with no data.</returns>
#pragma warning disable CS8601 // Possible null reference assignment.
public static DataResult<T> Fail<T>() => new()
{
IsSuccess = false,
Data = default
};
#pragma warning restore CS8601 // Possible null reference assignment.
}
}

View File

@@ -54,4 +54,8 @@
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DigitalData.Core.Application.Abstraction\DigitalData.Core.Application.Abstraction.csproj" />
</ItemGroup>
</Project>

View File

@@ -3,8 +3,8 @@ using System.DirectoryServices;
using Microsoft.Extensions.Caching.Memory;
using System.DirectoryServices.AccountManagement;
using Microsoft.Extensions.Options;
using DigitalData.Core.Application.Interfaces;
using DigitalData.Core.Application.DTO;
using DigitalData.Core.Application.Abstraction.DTO;
using DigitalData.Core.Application.Abstraction;
namespace DigitalData.Core.Application
{

View File

@@ -1,94 +0,0 @@
namespace DigitalData.Core.Application;
/// <summary>
/// Provides extension methods for retrieving the value of an 'Id' property from objects.
/// </summary>
public static class EntityExtensions
{
/// <summary>
/// Attempts to retrieve the value of the 'Id' property from the specified object.
/// </summary>
/// <typeparam name="TId">The expected type of the 'Id' property.</typeparam>
/// <param name="obj">The object from which to retrieve the 'Id' property.</param>
/// <returns>
/// The value of the 'Id' property if it exists and is of type <typeparamref name="TId"/>; otherwise, <c>default</c>.
/// </returns>
public static TId? GetIdOrDefault<TId>(this object? obj)
{
var prop = obj?.GetType().GetProperty("Id");
return prop is not null && prop.GetValue(obj) is TId id ? id : default;
}
/// <summary>
/// Retrieves the value of the 'Id' property from the specified object, or throws an exception if not found or of the wrong type.
/// </summary>
/// <typeparam name="TId">The expected type of the 'Id' property.</typeparam>
/// <param name="obj">The object from which to retrieve the 'Id' property.</param>
/// <returns>The value of the 'Id' property.</returns>
/// <exception cref="InvalidOperationException">
/// Thrown if the object does not have a readable 'Id' property of type <typeparamref name="TId"/>.
/// </exception>
public static TId GetId<TId>(this object? obj)
=> obj.GetIdOrDefault<TId>()
?? throw new InvalidOperationException($"The object of type '{obj?.GetType().FullName ?? "null"}' does not have a readable 'Id' property of type '{typeof(TId).FullName}'.");
/// <summary>
/// Tries to retrieve the value of the 'Id' property from the specified object.
/// </summary>
/// <typeparam name="TId">The expected type of the 'Id' property.</typeparam>
/// <param name="obj">The object from which to retrieve the 'Id' property.</param>
/// <param name="id">When this method returns, contains the value of the 'Id' property if found; otherwise, the default value for the type.</param>
/// <returns>
/// <c>true</c> if the 'Id' property was found and is of type <typeparamref name="TId"/>; otherwise, <c>false</c>.
/// </returns>
public static bool TryGetId<TId>(object? obj, out TId id)
{
#pragma warning disable CS8601
id = obj.GetIdOrDefault<TId>();
#pragma warning restore CS8601
return id is not null;
}
/// <summary>
/// Attempts to retrieve the value of the 'Id' property from the specified object.
/// </summary>
/// <param name="obj">The object from which to retrieve the 'Id' property.</param>
/// <returns>
/// The value of the 'Id' property if it exists; otherwise, <c>null</c>.
/// </returns>
public static object? GetIdOrDefault(this object? obj)
{
var prop = obj?.GetType().GetProperty("Id");
return prop?.GetValue(obj);
}
/// <summary>
/// Retrieves the value of the 'Id' property from the specified object, or throws an exception if not found.
/// </summary>
/// <param name="obj">The object from which to retrieve the 'Id' property.</param>
/// <returns>The value of the 'Id' property.</returns>
/// <exception cref="InvalidOperationException">
/// Thrown if the object does not have a readable 'Id' property.
/// </exception>
public static object GetId(this object? obj)
=> obj.GetIdOrDefault()
?? throw new InvalidOperationException($"The object of type '{obj?.GetType().FullName ?? "null"}' does not have a readable 'Id' property.");
/// <summary>
/// Tries to retrieve the value of the 'Id' property from the specified object.
/// </summary>
/// <param name="obj">The object from which to retrieve the 'Id' property.</param>
/// <param name="id">
/// When this method returns, contains the value of the 'Id' property if found; otherwise, <c>null</c>.
/// </param>
/// <returns>
/// <c>true</c> if the 'Id' property was found; otherwise, <c>false</c>.
/// </returns>
public static bool TryGetId(object? obj, out object id)
{
#pragma warning disable CS8601
id = obj.GetIdOrDefault();
#pragma warning restore CS8601
return id is not null;
}
}

View File

@@ -1,21 +0,0 @@
namespace DigitalData.Core.Application.Interfaces
{
/// <summary>
/// Implements a simplified CRUD service interface that uses a single Data Transfer Object (DTO) type for all CRUD operations,
/// streamlining the process for entities where the same DTO can be used for creating, reading, updating, and deleting entities.
/// This interface inherits from the ICRUDService interface, applying the same DTO type for all generic type parameters,
/// thereby simplifying the usage for cases where a single DTO is sufficient for all operations on an entity.
/// </summary>
/// <typeparam name="TDto">The type of the Data Transfer Object used for all CRUD operations.</typeparam>
/// <typeparam name="TEntity">The type of the entity this service maps to.</typeparam>
/// <typeparam name="TId">The type of the identifier for the entity.</typeparam>
/// <remarks>
/// This interface is useful for entities that do not require different DTOs for different operations,
/// allowing for a more concise and maintainable codebase when implementing services for such entities.
/// </remarks>
[Obsolete("Use MediatR")]
public interface IBasicCRUDService<TDto, TEntity, TId> : ICRUDService<TDto, TDto, TEntity, TId>
where TDto : class where TEntity : class
{
}
}

View File

@@ -1,25 +0,0 @@
using DigitalData.Core.Application.DTO;
namespace DigitalData.Core.Application.Interfaces
{
[Obsolete("Use MediatR")]
public interface ICRUDService<TCreateDto, TReadDto, TEntity, TId> : IReadService<TReadDto, TEntity, TId>
where TCreateDto : class where TReadDto : class where TEntity : class
{
/// <summary>
/// Asynchronously creates a new entity based on the provided <paramref name="createDto"/> and returns the identifier of the created entity wrapped in a <see cref="DataResult{TId}"/>.
/// The <see cref="DataResult{TId}"/> contains the identifier of the newly created entity on success or an error message on failure.
/// </summary>
/// <param name="createDto">The data transfer object containing the information for the new entity.</param>
/// <returns>A task representing the asynchronous operation, with a <see cref="DataResult{TId}"/> containing the identifier of the created entity or an error message.</returns>
Task<DataResult<TReadDto>> CreateAsync(TCreateDto createDto);
/// <summary>
/// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage,
/// indicating the success or failure of the operation, including the error messages on failure.
/// </summary>
/// <param name="updateDto">The updateDTO with updated values for the entity.</param>
/// <returns>An Result indicating the outcome of the update operation, with an appropriate message.</returns>
Task<Result> UpdateAsync<TUpdateDto>(TUpdateDto updateDto);
}
}

View File

@@ -1,94 +0,0 @@
using DigitalData.Core.Application.DTO;
using System.DirectoryServices;
namespace DigitalData.Core.Application.Interfaces
{
public interface IDirectorySearchService
{
public string ServerName { get; }
public string Root { get; }
string SearchRootPath { get; }
Dictionary<string, string> CustomSearchFilters { get; }
/// <summary>
/// Creates the connections to the server and returns a Boolean value that specifies
/// whether the specified username and password are valid.
/// </summary>
/// <param name="userName">The username that is validated on the server. See the Remarks section
/// for more information on the format of userName.</param>
/// <param name="password">The password that is validated on the server.</param>
/// <returns>True if the credentials are valid; otherwise, false.</returns>
bool ValidateCredentials(string userName, string password);
/// <summary>
/// Creates the connections to the server asynchronously and returns a Boolean value that specifies
/// whether the specified username and password are valid.
/// </summary>
/// <param name="userName">The username that is validated on the server. See the Remarks section
/// for more information on the format of userName.</param>
/// <param name="password">The password that is validated on the server.</param>
/// <returns>True if the credentials are valid; otherwise, false.</returns>
Task<bool> ValidateCredentialsAsync(string userName, string password);
/// <summary>
/// Finds all directory entries matching the specified filter.
/// </summary>
/// <param name="searchRoot">The search root.</param>
/// <param name="filter">The search filter.</param>
/// <param name="searchScope">The search scope.</param>
/// <param name="sizeLimit">The size limit.</param>
/// <param name="properties">The properties to load.</param>
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
DataResult<IEnumerable<ResultPropertyCollection>> FindAll(DirectoryEntry searchRoot, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
/// <summary>
/// Finds all directory entries matching the specified filter asynchronously.
/// </summary>
/// <param name="searchRoot">The search root.</param>
/// <param name="filter">The search filter.</param>
/// <param name="searchScope">The search scope.</param>
/// <param name="sizeLimit">The size limit.</param>
/// <param name="properties">The properties to load.</param>
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
Task<DataResult<IEnumerable<ResultPropertyCollection>>> FindAllAsync(DirectoryEntry searchRoot, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
/// <summary>
/// Finds all directory entries matching the specified filter, using the user cache.
/// </summary>
/// <param name="username">The username.</param>
/// <param name="filter">The search filter.</param>
/// <param name="searchScope">The search scope.</param>
/// <param name="sizeLimit">The size limit.</param>
/// <param name="properties">The properties to load.</param>
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
DataResult<IEnumerable<ResultPropertyCollection>> FindAllByUserCache(string username, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
/// <summary>
/// Finds all directory entries matching the specified filter asynchronously, using the user cache.
/// </summary>
/// <param name="username">The username.</param>
/// <param name="filter">The search filter.</param>
/// <param name="searchScope">The search scope.</param>
/// <param name="sizeLimit">The size limit.</param>
/// <param name="properties">The properties to load.</param>
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
Task<DataResult<IEnumerable<ResultPropertyCollection>>> FindAllByUserCacheAsync(string username, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
/// <summary>
/// Sets the search root in the cache.
/// </summary>
/// <param name="username">The directory entry username.</param>
/// <param name="password">The directory entry password.</param>
void SetSearchRootCache(string username, string password);
/// <summary>
/// Gets the search root from the cache.
/// </summary>
/// <param name="username">The directory entry username.</param>
/// <returns>The cached <see cref="DirectoryEntry"/> if found; otherwise, null.</returns>
DirectoryEntry? GetSearchRootCache(string username);
}
}

View File

@@ -1,41 +0,0 @@
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Cryptography;
namespace DigitalData.Core.Application.Interfaces
{
/// <summary>
/// Defines the operations for JWT service handling claims of type <typeparamref name="TClaimValue"/>.
/// </summary>
public interface IJWTService<TClaimValue>
{
/// <summary>
/// Generates a symmetric security key with the specified byte size.
/// </summary>
/// <param name="byteSize">The size of the security key in bytes. Default is 32 bytes.</param>
/// <returns>A new instance of <see cref="SymmetricSecurityKey"/>.</returns>
public static SymmetricSecurityKey GenerateSecurityKey(int byteSize = 32)
{
using var rng = RandomNumberGenerator.Create();
var randomBytes = new byte[byteSize];
rng.GetBytes(randomBytes);
var securityKey = new SymmetricSecurityKey(randomBytes);
return securityKey;
}
/// <summary>
/// Generates a token based on the specified claim value.
/// </summary>
/// <param name="claimValue">The claim value to encode in the token.</param>
/// <returns>A JWT as a string.</returns>
string GenerateToken(TClaimValue claimValue);
/// <summary>
/// Reads and validates a security token from a string representation.
/// </summary>
/// <param name="token">The JWT to read.</param>
/// <returns>A <see cref="JwtSecurityToken"/> if the token is valid; otherwise, null.</returns>
JwtSecurityToken? ReadSecurityToken(string token);
}
}

View File

@@ -1,39 +0,0 @@
using DigitalData.Core.Application.DTO;
namespace DigitalData.Core.Application.Interfaces
{
[Obsolete("Use MediatR")]
public interface IReadService<TReadDto, TEntity, TId>
where TReadDto : class where TEntity : class
{
/// <summary>
/// Retrieves an entity by its identifier and returns its readDTO representation wrapped in an IServiceResult,
/// including the readDTO on success or null and an error message on failure.
/// </summary>
/// <param name="id">The identifier of the entity to retrieve.</param>
/// <returns>An DataResult containing the readDTO representing the found entity or null, with an appropriate message.</returns>
Task<DataResult<TReadDto>> ReadByIdAsync(TId id);
/// <summary>
/// Retrieves all entities and returns their readDTO representations wrapped in an IServiceResult,
/// including a collection of readDTOs on success or an error message on failure.
/// </summary>
/// <returns>An DataResult containing a collection of readDTOs representing all entities or an error message.</returns>
Task<DataResult<IEnumerable<TReadDto>>> ReadAllAsync();
/// <summary>
/// Deletes an entity by its identifier and returns the result wrapped in an IServiceMessage,
/// indicating the success or failure of the operation, including the error messages on failure.
/// </summary>
/// <param name="id">The identifier of the entity to delete.</param>
/// <returns>An Result indicating the outcome of the delete operation, with an appropriate message.</returns>
Task<Result> DeleteAsyncById(TId id);
/// <summary>
/// Asynchronously checks if an entity with the specified identifier exists within the data store.
/// </summary>
/// <param name="id">The identifier of the entity to check.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the entity exists.</returns>
Task<bool> HasEntity(TId id);
}
}

View File

@@ -1,34 +0,0 @@
using System.Linq.Expressions;
namespace DigitalData.Core.Application.Interfaces.Repository;
public static class Extensions
{
#region Create
public static Task<TEntity> CreateAsync<TEntity, TDto>(this IRepository<TEntity> repository, TDto dto, CancellationToken ct = default)
{
var entity = repository.Mapper.Map(dto);
return repository.CreateAsync(entity, ct);
}
public static Task<IEnumerable<TEntity>> CreateAsync<TEntity, TDto>(this IRepository<TEntity> repository, IEnumerable<TDto> dtos, CancellationToken ct = default)
{
var entities = dtos.Select(dto => repository.Mapper.Map(dto));
return repository.CreateAsync(entities, ct);
}
#endregion
#region Read
public static async Task<TEntity?> ReadFirstOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAllAsync(expression)).FirstOrDefault();
public static async Task<TEntity> ReadFirstAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAllAsync(expression)).First();
public static async Task<TEntity?> ReadSingleOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAllAsync(expression)).SingleOrDefault();
public static async Task<TEntity> ReadSingleAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAllAsync(expression)).Single();
#endregion
}

View File

@@ -1,63 +0,0 @@
namespace DigitalData.Core.Application.Interfaces.Repository
{
/// <summary>
/// Defines the contract for CRUD operations on a repository for entities of type TEntity.
/// </summary>
/// <typeparam name="TEntity">The type of the entity this repository works with.</typeparam>
/// <typeparam name="TId">The type of the identifier for the entity.</typeparam>
[Obsolete("Use IRepository")]
public interface ICRUDRepository<TEntity, TId> where TEntity : class
{
/// <summary>
/// Adds a new entity to the repository.
/// </summary>
/// <param name="entity">The entity to add.</param>
/// <returns>The added entity, or null if the entity cannot be added.</returns>
Task<TEntity?> CreateAsync(TEntity entity);
/// <summary>
/// Retrieves an entity by its identifier from the repository.
/// </summary>
/// <param name="id">The identifier of the entity to retrieve.</param>
/// <returns>The entity found, or null if no entity is found.</returns>
Task<TEntity?> ReadByIdAsync(TId id);
/// <summary>
/// Retrieves all entities from the repository.
/// </summary>
/// <returns>A collection of all entities.</returns>
Task<IEnumerable<TEntity>> ReadAllAsync();
/// <summary>
/// Updates an existing entity in the repository.
/// </summary>
/// <param name="entity">The entity to update.</param>
/// <returns>The updated entity.</returns>
Task<bool> UpdateAsync(TEntity entity);
/// <summary>
/// Deletes an entity from the repository.
/// </summary>
/// <param name="entity">The entity to delete.</param>
/// <returns>If entity is deleted, return true othwerwise return false.</returns>
Task<bool> DeleteAsync(TEntity entity);
/// <summary>
/// Asynchronously counts all entities in the repository.
/// </summary>
/// <returns>The total number of entities in the repository.</returns>
Task<int> CountAsync();
/// <summary>
/// Asynchronously counts the number of entities in the repository that match a specific identifier.
/// </summary>
/// <param name="id">The identifier of the entities to count.</param>
/// <returns>The number of entities with the specified identifier.</returns>
/// <remarks>
/// This method provides a count of entities in the database that match the given identifier.
/// If there are multiple entities with the same identifier, they will all be counted.
/// The default implementation assumes that the identifier is unique for each entity.
/// </remarks>
Task<int> CountAsync(TId id);
}
}

View File

@@ -1,50 +0,0 @@
namespace DigitalData.Core.Application.Interfaces.Repository
{
/// <summary>
/// Defines methods for mapping between entities and Data Transfer Objects (DTOs).
/// </summary>
/// <typeparam name="TEntity">The type of the entity to be mapped.</typeparam>
public interface IEntityMapper<TEntity>
{
/// <summary>
/// Maps an entity to a DTO.
/// </summary>
/// <typeparam name="TDto">The type of the DTO to map to.</typeparam>
/// <param name="entity">The entity to be mapped.</param>
/// <returns>The mapped DTO.</returns>
TDto Map<TDto>(TEntity entity);
/// <summary>
/// Maps an entity list to a DTO list.
/// </summary>
/// <typeparam name="TDto">The type of the DTO to map to.</typeparam>
/// <param name="entities">The entity list to be mapped.</param>
/// <returns>The mapped DTO list.</returns>
IEnumerable<TDto> Map<TDto>(IEnumerable<TEntity> entities);
/// <summary>
/// Maps a DTO to an entity.
/// </summary>
/// <typeparam name="TDto">The type of the DTO to be mapped.</typeparam>
/// <param name="dto">The DTO to be mapped.</param>
/// <returns>The mapped entity.</returns>
TEntity Map<TDto>(TDto dto);
/// <summary>
/// Maps a DTO list to an entity list.
/// </summary>
/// <typeparam name="TDto">The type of the DTO to be mapped.</typeparam>
/// <param name="dtos">The DTO list to be mapped.</param>
/// <returns>The mapped entity list.</returns>
IEnumerable<TEntity> Map<TDto>(IEnumerable<TDto> dtos);
/// <summary>
/// Maps a DTO to an existing entity.
/// </summary>
/// <typeparam name="TDto">The type of the DTO to be mapped.</typeparam>
/// <param name="dto">The DTO to be mapped.</param>
/// <param name="entity">The existing entity to be updated with the mapped values.</param>
/// <returns>The updated entity.</returns>
TEntity Map<TDto>(TDto dto, TEntity entity);
}
}

View File

@@ -1,85 +0,0 @@
using System.Linq.Expressions;
namespace DigitalData.Core.Application.Interfaces.Repository;
/// <summary>
/// Provides methods for executing common queries on a given entity type.
/// This interface abstracts away the direct usage of ORM libraries (such as Entity Framework) for querying data
/// and provides asynchronous and synchronous operations for querying a collection or single entity.
/// </summary>
/// <typeparam name="TEntity">The type of the entity being queried.</typeparam>
public interface IReadQuery<TEntity>
{
/// <summary>
/// Adds a filter to the query using the specified predicate expression.
/// This method allows chaining multiple filter conditions to refine the query results.
/// </summary>
/// <param name="expression">An expression that defines the filter condition for the entity.</param>
/// <returns>The current <see cref="IReadQuery{TEntity}"/> instance with the applied filter.</returns>
public IReadQuery<TEntity> Where(Expression<Func<TEntity, bool>> expression);
/// <summary>
/// Asynchronously retrieves the first entity or a default value if no entity is found.
/// </summary>
/// <param name="cancellation">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the entity or a default value.</returns>
public Task<TEntity?> FirstOrDefaultAsync(CancellationToken cancellation = default);
/// <summary>
/// Asynchronously retrieves a single entity or a default value if no entity is found.
/// </summary>
/// <param name="cancellation">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the entity or a default value.</returns>
public Task<TEntity?> SingleOrDefaultAsync(CancellationToken cancellation = default);
/// <summary>
/// Asynchronously retrieves a list of entities.
/// </summary>
/// <param name="cancellation">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the list of entities.</returns>
public Task<IEnumerable<TEntity>> ToListAsync(CancellationToken cancellation = default);
/// <summary>
/// Asynchronously retrieves the first entity. Throws an exception if no entity is found.
/// </summary>
/// <param name="cancellation">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the first entity.</returns>
public Task<TEntity> FirstAsync(CancellationToken cancellation = default);
/// <summary>
/// Asynchronously retrieves a single entity. Throws an exception if no entity is found.
/// </summary>
/// <param name="cancellation">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the single entity.</returns>
public Task<TEntity> SingleAsync(CancellationToken cancellation = default);
/// <summary>
/// Synchronously retrieves the first entity or a default value if no entity is found.
/// </summary>
/// <returns>The first entity or a default value.</returns>
public TEntity? FirstOrDefault();
/// <summary>
/// Synchronously retrieves a single entity or a default value if no entity is found.
/// </summary>
/// <returns>The single entity or a default value.</returns>
public TEntity? SingleOrDefault();
/// <summary>
/// Synchronously retrieves a list of entities.
/// </summary>
/// <returns>The list of entities.</returns>
public IEnumerable<TEntity> ToList();
/// <summary>
/// Synchronously retrieves the first entity. Throws an exception if no entity is found.
/// </summary>
/// <returns>The first entity.</returns>
public TEntity First();
/// <summary>
/// Synchronously retrieves a single entity. Throws an exception if no entity is found.
/// </summary>
/// <returns>The single entity.</returns>
public TEntity Single();
}

View File

@@ -1,32 +0,0 @@
using System.Linq.Expressions;
namespace DigitalData.Core.Application.Interfaces.Repository;
public interface IRepository<TEntity>
{
public IEntityMapper<TEntity> Mapper { get; }
public Task<TEntity> CreateAsync(TEntity entity, CancellationToken cancellation = default);
public Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken cancellation = default);
public IReadQuery<TEntity> Read(params Expression<Func<TEntity, bool>>[] expressions);
public Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken cancellation = default);
public Task DeleteAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellation = default);
#region Obsolete
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
public Task<IEnumerable<TEntity>> ReadAllAsync(Expression<Func<TEntity, bool>>? expression = null, CancellationToken cancellation = default);
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
public Task<TEntity?> ReadOrDefaultAsync(Expression<Func<TEntity, bool>> expression, bool single = true, CancellationToken cancellation = default);
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
public Task<IEnumerable<TDto>> ReadAllAsync<TDto>(Expression<Func<TEntity, bool>>? expression = null, CancellationToken cancellation = default);
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
public Task<TDto?> ReadOrDefaultAsync<TDto>(Expression<Func<TEntity, bool>> expression, bool single = true, CancellationToken cancellation = default);
#endregion
}

View File

@@ -1,14 +0,0 @@
using System.Linq.Expressions;
namespace DigitalData.Core.Application.Interfaces.Repository;
public static class RepositoryExtensions
{
public static IReadQuery<TEntity> Where<TEntity>(this IReadQuery<TEntity> query, params Expression<Func<TEntity, bool>>[] expressions)
{
foreach (var expression in expressions)
query = query.Where(expression);
return query;
}
}

View File

@@ -1,4 +1,4 @@
using DigitalData.Core.Application.Interfaces;
using DigitalData.Core.Application.Abstraction;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Cryptography;

View File

@@ -1,7 +1,7 @@
using AutoMapper;
using DigitalData.Core.Application.DTO;
using DigitalData.Core.Application.Interfaces;
using DigitalData.Core.Application.Interfaces.Repository;
using DigitalData.Core.Application.Abstraction;
using DigitalData.Core.Application.Abstraction.DTO;
using DigitalData.Core.Application.Abstraction.Repository;
namespace DigitalData.Core.Application;