public static async Task StartupAsync(IServiceProvider serviceProvider) { ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ExecutionEnvironment environment = serviceProvider.GetRequiredService <ExecutionEnvironment>(); ApplicationConfiguration configuration = serviceProvider.GetRequiredService <ApplicationConfiguration>(); Logging.InitializeLogging(environment: environment, loggerFactory: loggerFactory, configuration: configuration.LoggingConfiguration, version: configuration.Version, tenant: configuration.Tenant); // resolve a logger ILogger <Startup> logger = loggerFactory.CreateLogger <Startup>(); logger.LogInformation(new EventId(id: 27), message: "Starting Labs Scaling Ethereum Server"); EthereumServices.ConfigureGasPriceRecommendationWatcher(serviceProvider: serviceProvider); EthereumServices.ConfigureEventProcessing(serviceProvider: serviceProvider); try { await EthereumServices.ClearEventProcessingDatabaseLocksAsync(serviceProvider : serviceProvider, logger : logger); await ObjectLockingServices.ClearLocksAsync(serviceProvider : serviceProvider, logger : logger); await EnableNetworksAsync(serviceProvider : serviceProvider, logger : logger); IConfigurationRoot ethereumConfigurationRoot = EthereumServices.GetEthereumConfiguration(ApplicationConfigLocator.ConfigurationFilesPath); IEthereumAccountsMigrator ethereumAccountsMigrator = serviceProvider.GetRequiredService <IEthereumAccountsMigrator>(); // Must do all of these BEFORE starting all services. await ethereumAccountsMigrator.ConfigureEthereumNetworkSettingsAsync(services : serviceProvider, configuration : ethereumConfigurationRoot, fateChannelTokenFundingSourceAction : (_, _, _) => { }); logger.LogInformation(new EventId(id: 28), message: "Labs Scaling Ethereum Services Started"); } catch (Exception exception) { logger.LogError(new EventId(id: exception.HResult), exception: exception, message: "Failed to start Labs Scaling Ethereum Server services"); throw; } }
/// <summary> /// Compose the application according to the supplied configuration /// </summary> /// <param name="services">The service collection to register services into.</param> /// <param name="applicationConfiguration">Application configuration.</param> public static void Configure(IServiceCollection services, ApplicationConfiguration applicationConfiguration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddSingleton(applicationConfiguration); services.AddSingleton(typeof(ExecutionEnvironment), implementationInstance: applicationConfiguration.Environment); services.AddHttpContextAccessor(); services.AddSingleton <IRandomSource, DefaultRandomSource>(); SecurityServices.ConfigureWalletSalt(services: services, walletSaltString: applicationConfiguration.WalletSalt); EthereumAccountsSetup.Configure(services); string configurationFolder = ApplicationConfigLocator.ConfigurationFilesPath; AlertDispatcherSetup.Configure(services: services, configuration: applicationConfiguration.Configuration, pluginsPath: configurationFolder); CommonMiddlewareServicesSetup.Configure(services: services); CommonServicesSetup.Configure(services); ContractsSetup.Configure(services); EthereumServices.ConfigureEthereumServices(services: services, configuration: applicationConfiguration); DatabaseSetup.Configure(services: services, configuration: applicationConfiguration.SqlServerConfiguration); ServiceInterfacesSetup.Configure(services); ServiceInterfaceHubSetup.Configure(services); ObjectLockingSetup.Configure(serviceCollection: services, applicationConfiguration.Environment.IsLocalOrTest()); LogicSetup.Configure(services: services, faucetConfiguration: applicationConfiguration.FaucetConfiguration, faucetBalanceConfiguration: applicationConfiguration.FaucetBalanceConfiguration, houseAlerterConfiguration: applicationConfiguration.HouseBalanceConfiguration); }
/// <summary> /// Called when the application is shutting down /// </summary> public static Task ShutdownAsync() { // Ensure any locks that were held are closed by the server on shutdown. return(Task.WhenAll(ObjectLockingServices.ClearLocksAsync(), EthereumServices.ClearEventProcessingDatabaseLocksAsync())); }