Modul-Views: parameterloser Ctor + Initialize() (Designer-öffenbar)
Der VS-WinForms-Designer braucht einen parameterlosen Konstruktor, um eine Form zu instanziieren. Die drei Views hatten nur einen DI-Ctor -> Designer hätte sie nicht öffnen können. Umgestellt auf das Core-View-Muster (DashboardView): - Parameterloser Ctor: InitializeComponent() + Event-Wiring. - Initialize(deps): Abhängigkeiten setzen + Daten laden. - Felder nullable + Null-Guards in den Handlern. - CopyTradingModule.RegisterUi: new View() + view.Initialize(...) statt DI-Ctor. Verifiziert: Build grün, --smoke-ui grün (3 Accounts / 32 Trader, alle Views OK). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
4caba5bfd1
commit
76007db93f
@@ -15,16 +15,13 @@ namespace PolyTrader.Modules.CopyTrading.Ui
|
||||
/// </summary>
|
||||
public partial class ClosedTradesView : Form
|
||||
{
|
||||
private readonly ICopyTradeLogRepository _tradeLog;
|
||||
private readonly TradingState _state;
|
||||
private readonly CopyTradingState _copyState;
|
||||
private ICopyTradeLogRepository? _tradeLog;
|
||||
private TradingState? _state;
|
||||
private CopyTradingState? _copyState;
|
||||
|
||||
public ClosedTradesView(ICopyTradeLogRepository tradeLog, TradingState state, CopyTradingState copyState)
|
||||
// Parameterloser Konstruktor für den WinForms-Designer.
|
||||
public ClosedTradesView()
|
||||
{
|
||||
_tradeLog = tradeLog;
|
||||
_state = state;
|
||||
_copyState = copyState;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
colEntry.DefaultCellStyle.Format = "F3";
|
||||
@@ -36,12 +33,21 @@ namespace PolyTrader.Modules.CopyTrading.Ui
|
||||
colClosedAt.DefaultCellStyle.Format = "dd.MM.yyyy HH:mm";
|
||||
|
||||
btnRefresh.Click += (_, _) => LoadData();
|
||||
}
|
||||
|
||||
/// <summary>Injiziert die Abhängigkeiten (nach der DI-Auflösung) und lädt die Daten.</summary>
|
||||
public void Initialize(ICopyTradeLogRepository tradeLog, TradingState state, CopyTradingState copyState)
|
||||
{
|
||||
_tradeLog = tradeLog;
|
||||
_state = state;
|
||||
_copyState = copyState;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
if (_tradeLog == null) return;
|
||||
|
||||
var rows = _tradeLog.Find(_ => true)
|
||||
.OrderByDescending(t => t.ClosedAt)
|
||||
.Select(t => new ClosedTradeRow
|
||||
@@ -80,14 +86,14 @@ namespace PolyTrader.Modules.CopyTrading.Ui
|
||||
private string ResolveAccount(int accountId, bool isDemo)
|
||||
{
|
||||
string suffix = isDemo ? " (Demo)" : "";
|
||||
if (_state.Accounts.TryGetValue(accountId, out var acc) && !string.IsNullOrEmpty(acc.Name))
|
||||
if (_state != null && _state.Accounts.TryGetValue(accountId, out var acc) && !string.IsNullOrEmpty(acc.Name))
|
||||
return acc.Name + suffix;
|
||||
return $"#{accountId}{suffix}";
|
||||
}
|
||||
|
||||
private string ResolveTrader(int traderId)
|
||||
{
|
||||
if (_copyState.Traders.TryGetValue(traderId, out var t) && !string.IsNullOrEmpty(t.DisplayName))
|
||||
if (_copyState != null && _copyState.Traders.TryGetValue(traderId, out var t) && !string.IsNullOrEmpty(t.DisplayName))
|
||||
return t.DisplayName;
|
||||
return traderId > 0 ? $"#{traderId}" : "Unbekannt";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user