fix: Release build breakage + Dapper mapping bugs in VS-03/VS-04/Phase3-K #30
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace KArtSell.Modules.ModelOperations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// KArtSell.BuildingBlocks.Data.DapperBootstrap sets Dapper's snake_case-to-PascalCase column
|
||||||
|
/// mapping via its own [ModuleInitializer], but that only fires once that assembly is actually
|
||||||
|
/// loaded into the process. Several Sql classes in this module (e.g. AuditSql, TradeSql) only
|
||||||
|
/// have a `using` for a BuildingBlocks namespace without ever touching a type from it at
|
||||||
|
/// runtime, so under test isolation - or any host that queries this module before touching
|
||||||
|
/// BuildingBlocks - the load (and the mapping) can be skipped, silently nulling out every
|
||||||
|
/// snake_case column. Every Sql class in this assembly is defined here, so a module initializer
|
||||||
|
/// in this assembly is guaranteed to run before any of them are used, regardless of what else
|
||||||
|
/// has loaded.
|
||||||
|
/// </summary>
|
||||||
|
internal static class DapperMappingBootstrap
|
||||||
|
{
|
||||||
|
#pragma warning disable CA2255
|
||||||
|
[ModuleInitializer]
|
||||||
|
#pragma warning restore CA2255
|
||||||
|
public static void Initialize()
|
||||||
|
{
|
||||||
|
Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,16 +21,6 @@ public class TradeSql : ITradeSql
|
|||||||
private readonly NpgsqlDataSource _dataSource;
|
private readonly NpgsqlDataSource _dataSource;
|
||||||
private readonly ILogger<TradeSql> _logger;
|
private readonly ILogger<TradeSql> _logger;
|
||||||
|
|
||||||
static TradeSql()
|
|
||||||
{
|
|
||||||
// KArtSell.BuildingBlocks.Data.DapperBootstrap sets this via [ModuleInitializer], but that
|
|
||||||
// only fires once its assembly is actually loaded into the process. Nothing in this class
|
|
||||||
// references a BuildingBlocks type, so under test isolation (or any host that queries Trade
|
|
||||||
// before touching BuildingBlocks) that assembly load - and the mapping - can be skipped,
|
|
||||||
// silently nulling out every snake_case column (kis_order_id, sell_decision_id, ...).
|
|
||||||
Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TradeSql(NpgsqlDataSource dataSource, ILogger<TradeSql> logger)
|
public TradeSql(NpgsqlDataSource dataSource, ILogger<TradeSql> logger)
|
||||||
{
|
{
|
||||||
_dataSource = dataSource;
|
_dataSource = dataSource;
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace KArtSell.Modules.SignalEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// See KArtSell.Modules.ModelOperations.DapperMappingBootstrap for the full rationale: Dapper's
|
||||||
|
/// snake_case-to-PascalCase column mapping is a process-wide static flag set via
|
||||||
|
/// KArtSell.BuildingBlocks.Data.DapperBootstrap's [ModuleInitializer], which only fires once
|
||||||
|
/// that assembly is loaded. This mirrors it locally so every Sql/reader class defined in this
|
||||||
|
/// assembly is guaranteed the mapping is on before its first query, regardless of load order.
|
||||||
|
/// </summary>
|
||||||
|
internal static class DapperMappingBootstrap
|
||||||
|
{
|
||||||
|
#pragma warning disable CA2255
|
||||||
|
[ModuleInitializer]
|
||||||
|
#pragma warning restore CA2255
|
||||||
|
public static void Initialize()
|
||||||
|
{
|
||||||
|
Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user