// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: AGPL-3.0-or-later WITH AdditionRef-Progmasoft-Patent-Grant-1.1 using Npgsql; using Progmasoft.Progmaweb.Api.Accounts; namespace Progmasoft.Progmaweb.Api.ViGet; /// Registers ViGet: its catalog beside the accounts, and the publishing of plugins. internal static class ViGetRegistration { /// Adds the services of ViGet. /// The services of the API. /// The configuration, whose section ViGet holds . /// Where the accounts are kept; the catalog is kept in the same place. public static void AddViGet( this IServiceCollection services, IConfiguration configuration, AccountStoreKind accountStore) { services.Configure(configuration.GetSection(ViGetOptions.SectionName)); if (accountStore is AccountStoreKind.PostgreSql) { services.AddSingleton(); services.AddHostedService(); } else { services.AddSingleton(); } services.AddSingleton(); } } /// Brings the ViGet tables to the current schema before the service accepts requests. /// Connections to the database of the accounts. /// Receives what was done. internal sealed class ViGetSchemaInitializer( NpgsqlDataSource dataSource, ILogger logger) : IHostedService { /// Writes the schema version and the number of steps taken at this start. private static readonly Action SchemaReport = LoggerMessage.Define( LogLevel.Information, new EventId(1, "ViGetSchema"), "The ViGet tables are at schema version {Version}; {Taken} step(s) were taken at this start."); /// public async Task StartAsync(CancellationToken cancellationToken) { int taken = await ViGetSchema.ApplyAsync(dataSource, cancellationToken); SchemaReport(logger, ViGetSchema.CurrentVersion, taken, null); } /// public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; }