- Aktualisiert `SQLExecutor<T>` um `ISQLExecutor<T>` zu implementieren und `IQueryExecutor<T>` für die weitere Abfrageausführung zurückzugeben. - Umstrukturierte Methoden zur Verwendung von `ToExecutor()` für die Konvertierung von rohen SQL-Abfragen in einen `IQueryExecutor<T>`. - Geänderter Konstruktor, um `IServiceProvider` für die Injektion von Abhängigkeiten von benutzerdefinierten SQL-Abfrageklassen zu akzeptieren.
31 lines
967 B
C#
31 lines
967 B
C#
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace EnvelopeGenerator.Infrastructure;
|
|
|
|
public sealed class SQLExecutor<T> : ISQLExecutor<T> where T : class
|
|
{
|
|
private readonly EGDbContext _context;
|
|
|
|
private readonly IServiceProvider _provider;
|
|
|
|
public SQLExecutor(EGDbContext context, IServiceProvider provider)
|
|
{
|
|
_context = context;
|
|
_provider = provider;
|
|
}
|
|
|
|
public IQueryExecutor<T> Execute(string sql, CancellationToken cancellation = default, params object[] parameters)
|
|
=> _context
|
|
.Set<T>()
|
|
.FromSqlRaw(sql, parameters)
|
|
.ToExecutor();
|
|
|
|
public IQueryExecutor<T> Execute<TSQL>(CancellationToken cancellation = default, params object[] parameters) where TSQL : ISQL<T>
|
|
{
|
|
var sql = _provider.GetRequiredService<TSQL>();
|
|
return Execute(sql.Raw);
|
|
}
|
|
}
|