Orlean (#32)
* Start building with orlean * Add missing file * Serialize grain state * Remove grain and proxies * update and add plan * Update a bit * Fix backtest grain * Fix backtest grain * Clean a bit
This commit is contained in:
@@ -42,6 +42,8 @@ using MediatR;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Managing.Bootstrap;
|
||||
@@ -60,9 +62,62 @@ public static class ApiBootstrap
|
||||
.AddInfrastructure(configuration)
|
||||
.AddWorkers(configuration)
|
||||
.AddFluentValidation()
|
||||
.AddMediatR();
|
||||
.AddMediatR()
|
||||
;
|
||||
}
|
||||
|
||||
// Note: IClusterClient is automatically available in co-hosting scenarios
|
||||
// through IGrainFactory. Services should inject IGrainFactory instead of IClusterClient
|
||||
// to avoid circular dependency issues during DI container construction.
|
||||
|
||||
public static IHostBuilder ConfigureOrleans(this IHostBuilder hostBuilder, IConfiguration configuration,
|
||||
bool isProduction)
|
||||
{
|
||||
var postgreSqlConnectionString = configuration.GetSection("Databases:PostgreSql")["ConnectionString"];
|
||||
|
||||
return hostBuilder.UseOrleans(siloBuilder =>
|
||||
{
|
||||
// Configure clustering
|
||||
if (isProduction && !string.IsNullOrEmpty(postgreSqlConnectionString))
|
||||
{
|
||||
// Production clustering configuration
|
||||
siloBuilder
|
||||
.UseAdoNetClustering(options =>
|
||||
{
|
||||
options.ConnectionString = postgreSqlConnectionString;
|
||||
options.Invariant = "Npgsql";
|
||||
})
|
||||
.UseAdoNetReminderService(options =>
|
||||
{
|
||||
options.ConnectionString = postgreSqlConnectionString;
|
||||
options.Invariant = "Npgsql";
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Development clustering configuration
|
||||
siloBuilder.UseLocalhostClustering();
|
||||
}
|
||||
|
||||
siloBuilder
|
||||
.ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Information))
|
||||
.UseDashboard(options => { })
|
||||
.AddMemoryGrainStorageAsDefault()
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
// Register existing services for Orleans DI
|
||||
// These will be available to grains through dependency injection
|
||||
services.AddTransient<IExchangeService, ExchangeService>();
|
||||
services.AddTransient<IAccountService, AccountService>();
|
||||
services.AddTransient<ITradingService, TradingService>();
|
||||
services.AddTransient<IMessengerService, MessengerService>();
|
||||
services.AddTransient<IBackupBotService, BackupBotService>();
|
||||
});
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
private static IServiceCollection AddApplication(this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<ITradingService, TradingService>();
|
||||
|
||||
Reference in New Issue
Block a user