71 lines
4.3 KiB
C#
71 lines
4.3 KiB
C#
using Baya.Application.Contracts.Common;
|
|
using Baya.Application.Contracts.Invoices;
|
|
using Baya.Application.Contracts.Payments;
|
|
using Baya.Infrastructure.CrossCutting.Seams;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Baya.Infrastructure.CrossCutting.ServiceConfiguration;
|
|
|
|
public static class ServiceCollectionExtension
|
|
{
|
|
/// <summary>
|
|
/// Registers the cross-cutting seams (time, PII encryption, cache, object storage, SMS) with their
|
|
/// in-memory/local mock implementations. Swapping in a real provider later is a registration change
|
|
/// here — callers depend only on the Application contracts. (The real in-app
|
|
/// <c>INotificationDispatcher</c> needs the database, so it is registered in the Persistence layer.)
|
|
/// </summary>
|
|
public static IServiceCollection AddCrossCuttingSeams(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.Configure<SeamOptions>(configuration.GetSection(SeamOptions.SectionName));
|
|
|
|
services.AddMemoryCache();
|
|
|
|
services.AddSingleton<IDateTimeProvider, SystemDateTimeProvider>();
|
|
services.AddSingleton<IFieldEncryptor, SymmetricFieldEncryptor>();
|
|
services.AddSingleton<ICacheService, MemoryCacheService>();
|
|
services.AddSingleton<IObjectStorage, LocalDiskObjectStorage>();
|
|
|
|
// OTP/SMS delivery rail (backend-phase-2). The mock logs the code; a real gateway client
|
|
// (Kavenegar/Ghasedak/SMS.ir) replaces this registration only.
|
|
services.AddSingleton<ISmsSender, LoggingSmsSender>();
|
|
|
|
// استعلام شبا IBAN-owner ↔ national-id inquiry (backend-phase-3). The mock returns a deterministic
|
|
// fake match; a real Finnotech/banking-bridge client replaces this registration only.
|
|
services.AddSingleton<IBankAccountOwnershipVerifier, MockBankAccountOwnershipVerifier>();
|
|
|
|
// Address geocoding (backend-phase-4). The mock derives deterministic coordinates around the city
|
|
// centroid with no network call; a real Neshan/Google geocoding client replaces this registration.
|
|
services.AddSingleton<IGeocoder, MockGeocoder>();
|
|
|
|
// Nurse-verification vendors (backend-phase-6). All three are deterministic mocks; a real Iranian
|
|
// e-KYC vendor / Shahkar bridge / (future) MoH-INO portal swaps in by a registration change only —
|
|
// no mock behaviour is baked into any handler call site.
|
|
services.AddSingleton<IShahkarVerifier, MockShahkarVerifier>();
|
|
services.AddSingleton<IIdentityKycProvider, MockIdentityKycProvider>();
|
|
services.AddSingleton<ICredentialVerifier, MockCredentialVerifier>();
|
|
|
|
// Payment-capture trigger (backend-phase-9). The mock returns a deterministic succeeded capture so
|
|
// ConvertRequestToBooking is testable now; in b10 the real card capture replaces this registration
|
|
// and calls ConvertRequestToBooking directly on a real payment_transactions.succeeded.
|
|
services.AddSingleton<IPaymentCaptureSimulator, MockPaymentCaptureSimulator>();
|
|
|
|
// Payments money-path seams (backend-phase-10). All four are deterministic mocks; a real card PSP /
|
|
// تسهیم split adapter (config-selected per payment_gateways.config_json), per-provider signature
|
|
// verifier, and StackExchange.Redis lock swap in by a registration change only — no mock behaviour is
|
|
// baked into any handler. The DB uniques/state-machine remain the authoritative money-path backstop.
|
|
services.AddSingleton<IPaymentProvider, MockPaymentProvider>();
|
|
services.AddSingleton<ISettlementSplitProvider, MockSettlementSplitProvider>();
|
|
services.AddSingleton<IWebhookVerifier, MockWebhookVerifier>();
|
|
services.AddSingleton<IDistributedLock, InProcessDistributedLock>();
|
|
|
|
// Refunds/invoices seams (backend-phase-11). سامانه مودیان e-invoicing is mocked (pending/no-ref by
|
|
// default; config can force registered). IBnplProvider is a thin local stub so the bnpl_revert refund
|
|
// path runs before b12 merges — b12 owns the real seam. Both swap in by a registration change only.
|
|
services.AddSingleton<IMoadianClient, MockMoadianClient>();
|
|
services.AddSingleton<IBnplProvider, MockBnplProvider>();
|
|
|
|
return services;
|
|
}
|
|
}
|