Files
managing-apps/src/Managing.Core/ServiceScopeHelpers.cs
Oda 422fecea7b Postgres (#30)
* Add postgres

* Migrate users

* Migrate geneticRequest

* Try to fix Concurrent call

* Fix asyncawait

* Fix async and concurrent

* Migrate backtests

* Add cache for user by address

* Fix backtest migration

* Fix not open connection

* Fix backtest command error

* Fix concurrent

* Fix all concurrency

* Migrate TradingRepo

* Fix scenarios

* Migrate statistic repo

* Save botbackup

* Add settings et moneymanagement

* Add bot postgres

* fix a bit more backups

* Fix bot model

* Fix loading backup

* Remove cache market for read positions

* Add workers to postgre

* Fix workers api

* Reduce get Accounts for workers

* Migrate synth to postgre

* Fix backtest saved

* Remove mongodb

* botservice decorrelation

* Fix tradingbot scope call

* fix tradingbot

* fix concurrent

* Fix scope for genetics

* Fix account over requesting

* Fix bundle backtest worker

* fix a lot of things

* fix tab backtest

* Remove optimized moneymanagement

* Add light signal to not use User and too much property

* Make money management lighter

* insert indicators to awaitable

* Migrate add strategies to await

* Refactor scenario and indicator retrieval to use asynchronous methods throughout the application

* add more async await

* Add services

* Fix and clean

* Fix bot a bit

* Fix bot and add message for cooldown

* Remove fees

* Add script to deploy db

* Update dfeeploy script

* fix script

* Add idempotent script and backup

* finish script migration

* Fix did user and agent name on start bot
2025-07-27 20:42:17 +07:00

67 lines
2.8 KiB
C#

using Microsoft.Extensions.DependencyInjection;
namespace Managing.Core
{
public static class ServiceScopeHelpers
{
public static async Task WithScopedService<TService>(IServiceScopeFactory scopeFactory, Func<TService, Task> action)
where TService : notnull
{
using var scope = scopeFactory.CreateScope();
var service = scope.ServiceProvider.GetRequiredService<TService>();
await action(service);
}
public static async Task<TResult> WithScopedService<TService, TResult>(IServiceScopeFactory scopeFactory, Func<TService, Task<TResult>> action)
where TService : notnull
{
using var scope = scopeFactory.CreateScope();
var service = scope.ServiceProvider.GetRequiredService<TService>();
return await action(service);
}
public static async Task WithScopedServices<T1, T2>(IServiceScopeFactory scopeFactory, Func<T1, T2, Task> action)
where T1 : notnull
where T2 : notnull
{
using var scope = scopeFactory.CreateScope();
var s1 = scope.ServiceProvider.GetRequiredService<T1>();
var s2 = scope.ServiceProvider.GetRequiredService<T2>();
await action(s1, s2);
}
public static async Task<TResult> WithScopedServices<T1, T2, TResult>(IServiceScopeFactory scopeFactory, Func<T1, T2, Task<TResult>> action)
where T1 : notnull
where T2 : notnull
{
using var scope = scopeFactory.CreateScope();
var s1 = scope.ServiceProvider.GetRequiredService<T1>();
var s2 = scope.ServiceProvider.GetRequiredService<T2>();
return await action(s1, s2);
}
public static async Task WithScopedServices<T1, T2, T3>(IServiceScopeFactory scopeFactory, Func<T1, T2, T3, Task> action)
where T1 : notnull
where T2 : notnull
where T3 : notnull
{
using var scope = scopeFactory.CreateScope();
var s1 = scope.ServiceProvider.GetRequiredService<T1>();
var s2 = scope.ServiceProvider.GetRequiredService<T2>();
var s3 = scope.ServiceProvider.GetRequiredService<T3>();
await action(s1, s2, s3);
}
public static async Task<TResult> WithScopedServices<T1, T2, T3, TResult>(IServiceScopeFactory scopeFactory, Func<T1, T2, T3, Task<TResult>> action)
where T1 : notnull
where T2 : notnull
where T3 : notnull
{
using var scope = scopeFactory.CreateScope();
var s1 = scope.ServiceProvider.GetRequiredService<T1>();
var s2 = scope.ServiceProvider.GetRequiredService<T2>();
var s3 = scope.ServiceProvider.GetRequiredService<T3>();
return await action(s1, s2, s3);
}
}
}