fleshout backend

This commit is contained in:
KS Jannette
2026-08-03 04:23:32 -04:00
parent a00282b1e6
commit 092ef17439
19 changed files with 500 additions and 52 deletions

View File

@@ -0,0 +1,37 @@
using Backend.Data.InMemory;
namespace Backend.Data;
/// <summary>
/// Single place where a storage backend is chosen. To add a real database, implement
/// <see cref="IUserRepository"/> and register it under a new provider name here;
/// controllers stay untouched.
/// </summary>
public static class PersistenceServiceCollectionExtensions
{
public static IServiceCollection AddPersistence(
this IServiceCollection services,
IConfiguration configuration)
{
services.Configure<PersistenceOptions>(configuration.GetSection(PersistenceOptions.SectionName));
var provider = configuration.GetSection(PersistenceOptions.SectionName).Get<PersistenceOptions>()?.Provider
?? PersistenceProviders.InMemory;
switch (provider)
{
case PersistenceProviders.InMemory:
// Singleton because the store itself holds the data.
services.AddSingleton<IUserRepository, InMemoryUserRepository>();
break;
default:
throw new InvalidOperationException(
$"Unknown persistence provider '{provider}'. Supported providers: " +
$"'{PersistenceProviders.InMemory}'. Register additional providers in " +
$"{nameof(PersistenceServiceCollectionExtensions)}.");
}
return services;
}
}