Files
Hy2026/backend/Infrastructure/DependencyInjection.cs
T
Rafał Tyński cadc321d96 feat(backend): add problem/need submission module with workflow and events
Add submission CRUD with pagination and role scoping, challenge/location binding, automatic keyword extraction, a validated status workflow, and domain events for matchmaking and notifications. Create a problem record together with each submission.
2026-10-04 02:22:00 +02:00

62 lines
2.3 KiB
C#

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SurrealDb.Net;
using TarninaHub.Application.Abstractions;
using TarninaHub.Infrastructure.Auth;
using TarninaHub.Infrastructure.Events;
using TarninaHub.Infrastructure.Persistence;
using TarninaHub.Infrastructure.Settings;
namespace TarninaHub.Infrastructure;
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(
this IServiceCollection services,
IConfiguration configuration)
{
services.Configure<SurrealDbSettings>(configuration.GetSection("SurrealDb"));
services.Configure<AuthSettings>(configuration.GetSection("Auth"));
var settings = configuration.GetSection("SurrealDb").Get<SurrealDbSettings>()
?? new SurrealDbSettings();
var options = new SurrealDbOptions
{
Endpoint = SurrealDbEndpoint.Build(settings),
Namespace = settings.Namespace,
Database = settings.Database,
};
if (string.IsNullOrWhiteSpace(settings.RemoteUrl))
{
// Embedded RocksDB, persisted next to the running app (./data), never in memory.
var dataDirectory = Path.Combine(AppContext.BaseDirectory, settings.DataDirectory);
Directory.CreateDirectory(dataDirectory);
services
.AddSurreal(options, ServiceLifetime.Singleton)
.AddRocksDbProvider();
}
else
{
// Remote SurrealDB server on its own dedicated port (used for sync with the frontend).
options.Username = settings.Username;
options.Password = settings.Password;
services.AddSurreal(options, ServiceLifetime.Singleton);
}
services.AddSingleton<IStorageService, StorageService>();
services.AddSingleton<IMigrationRunner, MigrationRunner>();
services.AddSingleton<ITokenService, TokenService>();
services.AddSingleton<IUserService, UserService>();
services.AddSingleton<IConsentService, ConsentService>();
services.AddSingleton<IAuditLogService, AuditLogService>();
services.AddSingleton<ISubmissionEventPublisher, LoggingSubmissionEventPublisher>();
services.AddSingleton<ISubmissionService, SubmissionService>();
return services;
}
}