Refactor DbModel options to use explicit, typed classes

Replaced the old generic, dictionary-based entity configuration system with a new, strongly-typed options structure under ReC.Application.Common.Options.DbModel. Introduced specific options classes for each major database view and result type, each with clear property mappings and defaults. Added a ViewOptions class for view/schema info. Removed all legacy entity mapping infrastructure, resulting in a more maintainable and type-safe configuration approach.
This commit is contained in:
2026-03-25 12:53:10 +01:00
parent 3d46901af5
commit a46cd08122
13 changed files with 130 additions and 65 deletions

View File

@@ -0,0 +1,6 @@
namespace ReC.Application.Common.Options.DbModel;
public class BodyQueryResultOptions
{
public string RawBody { get; set; } = "REQUEST_BODY";
}

View File

@@ -0,0 +1,16 @@
namespace ReC.Application.Common.Options.DbModel;
public class DbModelOptions
{
public RecActionViewOptions RecActionView { get; set; } = new();
public ProfileViewOptions ProfileView { get; set; } = new();
public ResultViewOptions ResultView { get; set; } = new();
public HeaderQueryResultOptions HeaderQueryResult { get; set; } = new();
public BodyQueryResultOptions BodyQueryResult { get; set; } = new();
public InsertObjectResultOptions InsertObjectResult { get; set; } = new();
}

View File

@@ -0,0 +1,6 @@
namespace ReC.Application.Common.Options.DbModel;
public class HeaderQueryResultOptions
{
public string RawHeader { get; set; } = "REQUEST_HEADER";
}

View File

@@ -0,0 +1,6 @@
namespace ReC.Application.Common.Options.DbModel;
public class InsertObjectResultOptions
{
public string NewObjectId { get; set; } = "oGUID";
}

View File

@@ -0,0 +1,25 @@
namespace ReC.Application.Common.Options.DbModel;
public class ProfileViewOptions
{
public ViewOptions View { get; set; } = new() { Name = "VWREC_PROFILE", Schema = "dbo" };
public string Id { get; set; } = "PROFILE_GUID";
public string Active { get; set; } = "ACTIVE";
public string TypeId { get; set; } = "TYPE_ID";
public string Type { get; set; } = "TYPE";
public string Mandantor { get; set; } = "MANDANTOR";
public string ProfileName { get; set; } = "PROFILE_NAME";
public string Description { get; set; } = "DESCRIPTION";
public string LogLevelId { get; set; } = "LOG_LEVEL_ID";
public string LogLevel { get; set; } = "LOG_LEVEL";
public string LanguageId { get; set; } = "LANGUAGE_ID";
public string Language { get; set; } = "LANGUAGE";
public string AddedWho { get; set; } = "ADDED_WHO";
public string AddedWhen { get; set; } = "ADDED_WHEN";
public string ChangedWho { get; set; } = "CHANGED_WHO";
public string ChangedWhen { get; set; } = "CHANGED_WHEN";
public string FirstRun { get; set; } = "FIRST_RUN";
public string LastRun { get; set; } = "LAST_RUN";
public string LastResult { get; set; } = "LAST_RESULT";
}

View File

@@ -0,0 +1,40 @@
namespace ReC.Application.Common.Options.DbModel;
public class RecActionViewOptions
{
public ViewOptions View { get; set; } = new() { Name = "VWREC_ACTION", Schema = "dbo" };
public string Id { get; set; } = "ACTION_GUID";
public string ProfileId { get; set; } = "PROFILE_ID";
public string ProfileName { get; set; } = "PROFILE_NAME";
public string ProfileType { get; set; } = "PROFILE_TYPE_ID";
public string Sequence { get; set; } = "SEQUENCE";
public string EndpointId { get; set; } = "ENDPOINT_ID";
public string EndpointUri { get; set; } = "ENDPOINT_URI";
public string EndpointAuthId { get; set; } = "ENDPOINT_AUTH_ID";
public string EndpointAuthType { get; set; } = "ENDPOINT_AUTH_TYPE_ID";
public string EndpointAuthTypeName { get; set; } = "ENDPOINT_AUTH_TYPE";
public string EndpointAuthApiKey { get; set; } = "ENDPOINT_AUTH_API_KEY";
public string EndpointAuthApiValue { get; set; } = "ENDPOINT_AUTH_API_VALUE";
public string EndpointAuthApiKeyAddTo { get; set; } = "ENDPOINT_AUTH_API_KEY_ADD_TO_ID";
public string EndpointAuthApiKeyAddToName { get; set; } = "ENDPOINT_AUTH_API_KEY_ADD_TO";
public string EndpointAuthToken { get; set; } = "ENDPOINT_AUTH_TOKEN";
public string EndpointAuthUsername { get; set; } = "ENDPOINT_AUTH_USERNAME";
public string EndpointAuthPassword { get; set; } = "ENDPOINT_AUTH_PASSWORD";
public string EndpointAuthDomain { get; set; } = "ENDPOINT_AUTH_DOMAIN";
public string EndpointAuthWorkstation { get; set; } = "ENDPOINT_AUTH_WORKSTATION";
public string EndpointParamsId { get; set; } = "ENDPOINT_PARAMS_ID";
public string SqlConnectionId { get; set; } = "SQL_CONNECTION_ID";
public string SqlConnectionServer { get; set; } = "SQL_CONNECTION_SERVER";
public string SqlConnectionDb { get; set; } = "SQL_CONNECTION_DB";
public string SqlConnectionUsername { get; set; } = "SQL_CONNECTION_USERNAME";
public string SqlConnectionPassword { get; set; } = "SQL_CONNECTION_PASSWORD";
public string RestType { get; set; } = "REST_TYPE_ID";
public string RestTypeName { get; set; } = "REST_TYPE";
public string PreprocessingQuery { get; set; } = "PREPROCESSING_QUERY";
public string HeaderQuery { get; set; } = "HEADER_QUERY";
public string BodyQuery { get; set; } = "BODY_QUERY";
public string PostprocessingQuery { get; set; } = "POSTPROCESSING_QUERY";
public string ErrorAction { get; set; } = "ERROR_ACTION_ID";
public string ErrorActionName { get; set; } = "ERROR_ACTION";
}

View File

@@ -0,0 +1,23 @@
namespace ReC.Application.Common.Options.DbModel;
public class ResultViewOptions
{
public ViewOptions View { get; set; } = new() { Name = "VWREC_RESULT", Schema = "dbo" };
public string Id { get; set; } = "RESULT_GUID";
public string ActionId { get; set; } = "ACTION_ID";
public string ProfileId { get; set; } = "PROFILE_ID";
public string ProfileName { get; set; } = "PROFILE_NAME";
public string StatusCode { get; set; } = "STATUS_ID";
public string StatusName { get; set; } = "STATUS";
public string Type { get; set; } = "RESULT_TYPE_ID";
public string TypeName { get; set; } = "RESULT_TYPE";
public string Header { get; set; } = "RESULT_HEADER";
public string Body { get; set; } = "RESULT_BODY";
public string Info { get; set; } = "RESULT_INFO";
public string Error { get; set; } = "RESULT_ERROR";
public string AddedWho { get; set; } = "ADDED_WHO";
public string AddedWhen { get; set; } = "ADDED_WHEN";
public string ChangedWho { get; set; } = "CHANGED_WHO";
public string ChangedWhen { get; set; } = "CHANGED_WHEN";
}

View File

@@ -0,0 +1,8 @@
namespace ReC.Application.Common.Options.DbModel;
public class ViewOptions
{
public string Name { get; set; } = null!;
public string Schema { get; set; } = "dbo";
}

View File

@@ -1,23 +0,0 @@
using ReC.Infrastructure.Exceptions;
using ReC.Infrastructure.Options.Shared;
namespace ReC.Infrastructure.Options;
public record DbModelOptions
{
public Dictionary<string, EntityOptions> Entities { get; init; } = [];
public Dictionary<string, VirtualEntityOptions> VirtualEntities { get; init; } = [];
public void EnsureEntity<T>(bool isVirtual)
{
var entities = isVirtual
? VirtualEntities.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as EntityBaseOptions)
: Entities.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as EntityBaseOptions);
if(entities.TryGetValue(nameof(T), out var entityOptions))
entityOptions.EnsureProperties<T>();
else
throw new DbModelConfigurationException($"Entity options for type '{typeof(T).FullName}' not found.");
}
}

View File

@@ -1,33 +0,0 @@
using ReC.Domain.Attributes;
using ReC.Infrastructure.Exceptions;
namespace ReC.Infrastructure.Options.Shared;
public record EntityBaseOptions()
{
public Dictionary<string, string> ColumnMappings { get; init; } = [];
public IEnumerable<string> PropertyNames => ColumnMappings.Select(col => col.Key);
public IEnumerable<string> ColumnNames => ColumnMappings.Select(col => col.Value);
public void EnsureProperties(IEnumerable<string> propertyNames)
{
var missingProperties = propertyNames.Except(PropertyNames).ToList();
if (missingProperties.Count != 0)
throw new DbModelConfigurationException($"The following properties are not configured: {string.Join(", ", missingProperties)}");
}
public void EnsureProperties(params string[] propertyNames)
=> EnsureProperties(propertyNames.AsEnumerable());
public void EnsureProperties<T>()
{
var propertyNames = typeof(T)
.GetProperties()
.Where(prop => Attribute.IsDefined(prop, typeof(MustConfiguredAttribute)))
.Select(prop => prop.Name);
EnsureProperties(propertyNames);
}
}

View File

@@ -1,3 +0,0 @@
namespace ReC.Infrastructure.Options.Shared;
public record EntityOptions(TableOptions Table) : EntityBaseOptions;

View File

@@ -1,3 +0,0 @@
namespace ReC.Infrastructure.Options.Shared;
public record TableOptions(string Name, string? Schema = null);

View File

@@ -1,3 +0,0 @@
namespace ReC.Infrastructure.Options.Shared;
public record VirtualEntityOptions : EntityBaseOptions;