2026-01-18 02:52:30 +01:00
|
|
|
using Books.Api.EventFlow.ReadModels;
|
|
|
|
|
using Books.Api.EventFlow.Repositories;
|
|
|
|
|
using EventFlow;
|
|
|
|
|
using EventFlow.Extensions;
|
|
|
|
|
using EventFlow.PostgreSql.Extensions;
|
|
|
|
|
using EventFlow.Sql.ReadModels;
|
|
|
|
|
using ReadModelSqlGenerator = Books.Api.EventFlow.Customs.ReadModelSqlGenerator;
|
|
|
|
|
|
|
|
|
|
namespace Books.Api.EventFlow.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class ReadModelRegistrationExtensions
|
|
|
|
|
{
|
|
|
|
|
public static IEventFlowOptions AddReadModels(this IEventFlowOptions options)
|
|
|
|
|
{
|
|
|
|
|
return options
|
|
|
|
|
.UsePostgreSqlReadModel<CompanyReadModel, CompanyReadModelLocator>()
|
2026-01-18 11:49:29 +01:00
|
|
|
.UsePostgreSqlReadModel<ApiKeyReadModel, ApiKeyReadModelLocator>()
|
|
|
|
|
.RegisterServices(sr => sr.AddSingleton<IReadModelSqlGenerator>(new ReadModelSqlGenerator()));
|
2026-01-18 02:52:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IServiceCollection AddRepositories(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
// Register locators
|
|
|
|
|
services.AddTransient<CompanyReadModelLocator>();
|
2026-01-18 11:49:29 +01:00
|
|
|
services.AddTransient<ApiKeyReadModelLocator>();
|
2026-01-18 02:52:30 +01:00
|
|
|
|
|
|
|
|
// Register repositories
|
|
|
|
|
services.AddScoped<ICompanyRepository, CompanyRepository>();
|
2026-01-18 11:49:29 +01:00
|
|
|
services.AddScoped<IApiKeyRepository, ApiKeyRepository>();
|
2026-01-18 02:52:30 +01:00
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|