Phase 6 (Stufe 2): Core-EF-Repos + umschaltbare Registrierung
- EF-Implementierungen hinter den Core-Interfaces: EfAccountRepository, EfMarketRepository, EfPositionRepository, EfTradeLogRepository. Thread-safe via IDbContextFactory<CoreDbContext> (kurzlebiger Context je Operation). - AddCorePersistence(DatabaseOptions): Provider "MySql" -> EF + DbContextFactory, "Mongo" -> Mongo-Repos. Program.cs uebergibt die aufgeloesten Optionen. - appsettings.json Provider-Default = "Mongo" (App bleibt vorerst auf MongoDB, kein Verhaltenswechsel). MySQL-Connection liegt in gitignorierter appsettings.Local.json. - Build 0 Fehler. Naechste Stufen: Modul-Context + EF-Repos (inkl. trackers/mt_history), Config-Migration Mongo->MySQL, dann Provider umschalten + Mongo entfernen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ad9bb684d4
commit
d8cfdbf6be
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PolyTraderSharp.Models;
|
||||
|
||||
namespace PolyTrader.Core.Persistence.Ef
|
||||
{
|
||||
public class EfTradeLogRepository : ITradeLogRepository
|
||||
{
|
||||
private readonly IDbContextFactory<CoreDbContext> _factory;
|
||||
|
||||
public EfTradeLogRepository(IDbContextFactory<CoreDbContext> factory) => _factory = factory;
|
||||
|
||||
// Indizes werden über die EF-Migration erstellt.
|
||||
public void EnsureIndexes() { }
|
||||
|
||||
public void Insert(TradeRecord record)
|
||||
{
|
||||
using var ctx = _factory.CreateDbContext();
|
||||
ctx.TradeLog.Add(record);
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
public List<TradeRecord> GetRecent(int limit)
|
||||
{
|
||||
using var ctx = _factory.CreateDbContext();
|
||||
return ctx.TradeLog.AsNoTracking().OrderByDescending(x => x.ClosedAt).Take(limit).ToList();
|
||||
}
|
||||
|
||||
public List<TradeRecord> Find(Expression<Func<TradeRecord, bool>> predicate)
|
||||
{
|
||||
using var ctx = _factory.CreateDbContext();
|
||||
return ctx.TradeLog.AsNoTracking().Where(predicate).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user