arolariu.Backend.Domain.Invoices.Services.Foundation.MerchantStorage
arolariu.Backend.Domain.Invoices
arolariu.Backend.Domain.Invoices.Services.Foundation.MerchantStorage Namespace
Classes
MerchantStorageFoundationService Class
Class that implements the merchant storage foundation service.
public class MerchantStorageFoundationService : arolariu.Backend.Domain.Invoices.Services.Foundation.MerchantStorage.IMerchantStorageFoundationService
Inheritance System.Object 🡒 MerchantStorageFoundationService
Implements IMerchantStorageFoundationService
Constructors
MerchantStorageFoundationService(IInvoiceNoSqlBroker, ILoggerFactory) Constructor
Public constructor.
public MerchantStorageFoundationService(arolariu.Backend.Domain.Invoices.Brokers.DatabaseBroker.IInvoiceNoSqlBroker invoiceNoSqlBroker, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory);
Parameters
invoiceNoSqlBroker IInvoiceNoSqlBroker
loggerFactory Microsoft.Extensions.Logging.ILoggerFactory
Fields
MerchantStorageFoundationService.invoiceNoSqlBroker Field
private readonly IInvoiceNoSqlBroker invoiceNoSqlBroker;
Field Value
MerchantStorageFoundationService.logger Field
private readonly ILogger<IMerchantStorageFoundationService> logger;
Field Value
Microsoft.Extensions.Logging.ILogger<IMerchantStorageFoundationService>
Methods
MerchantStorageFoundationService.Classify(Exception) Method
private System.Exception Classify(System.Exception exception);
Parameters
exception System.Exception
Returns
MerchantStorageFoundationService.CreateMerchantObject(Merchant, Nullable<Guid>, CancellationToken) Method
Persists a new Merchant aggregate.
public System.Threading.Tasks.Task CreateMerchantObject(arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant merchant, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
merchant Merchant
Merchant aggregate to persist (MUST NOT be null).
parentCompanyId System.Nullable<System.Guid>
Optional tenancy / partition discriminator.
cancellationToken System.Threading.CancellationToken
Optional cancellation token to abort the operation.
Implements CreateMerchantObject(Merchant, Nullable<Guid>, CancellationToken)
Returns
System.Threading.Tasks.Task
Asynchronous task.
Exceptions
System.OperationCanceledException
Thrown if the operation is cancelled.
Remarks
Validation: Ensures merchant id not empty, required collections (e.g. ReferencedInvoices) initialized, and category values within allowed domain.
Failure Modes: Throws validation exceptions on invariant breach, dependency / dependency validation exceptions on broker-level persistence failures (conflicts, connectivity, serialization).
MerchantStorageFoundationService.DeleteMerchantObject(Guid, Nullable<Guid>, CancellationToken) Method
Deletes (logical or physical) a merchant.
public System.Threading.Tasks.Task DeleteMerchantObject(System.Guid identifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
identifier System.Guid
Merchant identifier.
parentCompanyId System.Nullable<System.Guid>
Optional partition discriminator.
cancellationToken System.Threading.CancellationToken
Optional cancellation token to abort the operation.
Implements DeleteMerchantObject(Guid, Nullable<Guid>, CancellationToken)
Returns
System.Threading.Tasks.Task
Asynchronous task.
Exceptions
System.OperationCanceledException
Thrown if the operation is cancelled.
Remarks
Idempotency: Repeated deletes yield same terminal state (absent / marked deleted).
Referential Integrity: This layer DOES NOT cascade / clean invoice references (belongs to orchestration / processing layers).
MerchantStorageFoundationService.LogAndWrapDependency(Exception) Method
private arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Exceptions.Outer.Foundation.MerchantFoundationServiceDependencyException LogAndWrapDependency(System.Exception exception);
Parameters
exception System.Exception
Returns
MerchantFoundationServiceDependencyException
MerchantStorageFoundationService.LogAndWrapDependencyValidation(Exception) Method
private arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Exceptions.Outer.Foundation.MerchantFoundationServiceDependencyValidationException LogAndWrapDependencyValidation(System.Exception exception);
Parameters
exception System.Exception
Returns
MerchantFoundationServiceDependencyValidationException
MerchantStorageFoundationService.LogAndWrapService(Exception) Method
private arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Exceptions.Outer.Foundation.MerchantFoundationServiceException LogAndWrapService(System.Exception exception);
Parameters
exception System.Exception
Returns
MerchantFoundationServiceException
MerchantStorageFoundationService.LogAndWrapValidation(Exception) Method
private arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Exceptions.Outer.Foundation.MerchantFoundationServiceValidationException LogAndWrapValidation(System.Exception exception);
Parameters
exception System.Exception
Returns
MerchantFoundationServiceValidationException
MerchantStorageFoundationService.ReadAllMerchantObjects(Guid, CancellationToken) Method
Enumerates all merchants under a partition (or across all when partition omitted).
public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant>> ReadAllMerchantObjects(System.Guid parentCompanyId, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
parentCompanyId System.Guid
Partition discriminator.
cancellationToken System.Threading.CancellationToken
Optional cancellation token to abort the operation.
Implements ReadAllMerchantObjects(Guid, CancellationToken)
Returns
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Merchant>>
Enumerable (empty if none).
Exceptions
System.OperationCanceledException
Thrown if the operation is cancelled.
Remarks
Pagination: Not implemented; large sets could be expensive (backlog: add paging and continuation tokens).
Filtering: Soft-deleted entities SHOULD be excluded if soft delete introduced.
MerchantStorageFoundationService.ReadMerchantObject(Guid, Nullable<Guid>, CancellationToken) Method
Retrieves a merchant by identifier (and optional partition).
public System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant> ReadMerchantObject(System.Guid identifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
identifier System.Guid
Merchant identifier.
parentCompanyId System.Nullable<System.Guid>
Optional partition discriminator.
cancellationToken System.Threading.CancellationToken
Optional cancellation token to abort the operation.
Implements ReadMerchantObject(Guid, Nullable<Guid>, CancellationToken)
Returns
System.Threading.Tasks.Task<Merchant>
The merchant or null.
Exceptions
System.OperationCanceledException
Thrown if the operation is cancelled.
Remarks
Return Semantics: Returns merchant or null if not found (implementations MAY alternatively raise a not-found validation exception depending on policy consistency with invoice storage).
Performance: SHOULD use point read within partition; cross-partition read when parentCompanyId absent may degrade throughput.
MerchantStorageFoundationService.TryCatchAsync(ReturningMerchantFunction) Method
private System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant> TryCatchAsync(arolariu.Backend.Domain.Invoices.Services.Foundation.MerchantStorage.MerchantStorageFoundationService.ReturningMerchantFunction returningMerchantFunction);
Parameters
returningMerchantFunction ReturningMerchantFunction()
Returns
System.Threading.Tasks.Task<Merchant>
MerchantStorageFoundationService.TryCatchAsync(ReturningMerchantsFunction) Method
private System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant>> TryCatchAsync(arolariu.Backend.Domain.Invoices.Services.Foundation.MerchantStorage.MerchantStorageFoundationService.ReturningMerchantsFunction returningMerchantsFunction);
Parameters
returningMerchantsFunction ReturningMerchantsFunction()
Returns
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Merchant>>
MerchantStorageFoundationService.TryCatchAsync(ReturningTaskFunction) Method
private System.Threading.Tasks.Task TryCatchAsync(arolariu.Backend.Domain.Invoices.Services.Foundation.MerchantStorage.MerchantStorageFoundationService.ReturningTaskFunction returningTaskFunction);
Parameters
returningTaskFunction ReturningTaskFunction()
Returns
MerchantStorageFoundationService.UpdateMerchantObject(Merchant, Guid, Nullable<Guid>, CancellationToken) Method
Replaces existing merchant state with provided aggregate.
public System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant> UpdateMerchantObject(arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant updatedMerchant, System.Guid merchantIdentifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
updatedMerchant Merchant
New merchant state.
merchantIdentifier System.Guid
Identifier of merchant being updated.
parentCompanyId System.Nullable<System.Guid>
Optional partition discriminator.
cancellationToken System.Threading.CancellationToken
Optional cancellation token to abort the operation.
Implements UpdateMerchantObject(Merchant, Guid, Nullable<Guid>, CancellationToken)
Returns
System.Threading.Tasks.Task<Merchant>
Updated merchant.
Exceptions
System.OperationCanceledException
Thrown if the operation is cancelled.
Remarks
Preconditions: Merchant MUST already exist; invariants re-validated for updated state.
Concurrency: No optimistic concurrency yet (backlog: ETag / version field).
MerchantStorageFoundationService.ValidateMerchantIdentifierIsSet(Nullable<Guid>) Method
private static void ValidateMerchantIdentifierIsSet(System.Nullable<System.Guid> identifier);
Parameters
identifier System.Nullable<System.Guid>
MerchantStorageFoundationService.ValidateParentCompanyIdentifierIsSet(Nullable<Guid>) Method
private static void ValidateParentCompanyIdentifierIsSet(System.Nullable<System.Guid> parentCompanyId);
Parameters
parentCompanyId System.Nullable<System.Guid>
Interfaces
IMerchantStorageFoundationService Interface
Foundation storage contract for persisting and retrieving Merchant aggregates.
public interface IMerchantStorageFoundationService
Derived
↳ MerchantStorageFoundationService
Remarks
Layer Role (The Standard): Direct broker-mediated CRUD plus invariant enforcement for a single aggregate type. NO cross-aggregate orchestration, NO multi-step workflows, NO external side-effects besides persistence.
Responsibilities:
- Create, read, enumerate, update, delete merchants.
- Validate structural and domain invariants (identifier, category validity, reference list initialization / bounds).
- Normalize or sanitize simple fields (e.g. trimming display names) when required.
Partitioning: Optional parentCompanyId acts as logical partition / tenancy discriminator. Implementations SHOULD route queries through this key for cost efficiency. Null may trigger cross-partition scans (backlog: disallow).
Thread-Safety: Implementations SHOULD be stateless; any caching must be concurrency-safe.
Idempotency: Create is non-idempotent (duplicate ids rejected); delete and update are idempotent with respect to final persisted state.
Soft Delete: If soft deletion is adopted in future, this contract MAY evolve; current semantics imply physical or logical removal as defined by implementation.
Methods
IMerchantStorageFoundationService.CreateMerchantObject(Merchant, Nullable<Guid>, CancellationToken) Method
Persists a new Merchant aggregate.
System.Threading.Tasks.Task CreateMerchantObject(arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant merchant, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
merchant Merchant
Merchant aggregate to persist (MUST NOT be null).
parentCompanyId System.Nullable<System.Guid>
Optional tenancy / partition discriminator.
cancellationToken System.Threading.CancellationToken
Optional cancellation token to abort the operation.
Returns
System.Threading.Tasks.Task
Asynchronous task.
Exceptions
System.OperationCanceledException
Thrown if the operation is cancelled.
Remarks
Validation: Ensures merchant id not empty, required collections (e.g. ReferencedInvoices) initialized, and category values within allowed domain.
Failure Modes: Throws validation exceptions on invariant breach, dependency / dependency validation exceptions on broker-level persistence failures (conflicts, connectivity, serialization).
IMerchantStorageFoundationService.DeleteMerchantObject(Guid, Nullable<Guid>, CancellationToken) Method
Deletes (logical or physical) a merchant.
System.Threading.Tasks.Task DeleteMerchantObject(System.Guid identifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
identifier System.Guid
Merchant identifier.
parentCompanyId System.Nullable<System.Guid>
Optional partition discriminator.
cancellationToken System.Threading.CancellationToken
Optional cancellation token to abort the operation.
Returns
System.Threading.Tasks.Task
Asynchronous task.
Exceptions
System.OperationCanceledException
Thrown if the operation is cancelled.
Remarks
Idempotency: Repeated deletes yield same terminal state (absent / marked deleted).
Referential Integrity: This layer DOES NOT cascade / clean invoice references (belongs to orchestration / processing layers).
IMerchantStorageFoundationService.ReadAllMerchantObjects(Guid, CancellationToken) Method
Enumerates all merchants under a partition (or across all when partition omitted).
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant>> ReadAllMerchantObjects(System.Guid parentCompanyId, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
parentCompanyId System.Guid
Partition discriminator.
cancellationToken System.Threading.CancellationToken
Optional cancellation token to abort the operation.
Returns
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Merchant>>
Enumerable (empty if none).
Exceptions
System.OperationCanceledException
Thrown if the operation is cancelled.
Remarks
Pagination: Not implemented; large sets could be expensive (backlog: add paging and continuation tokens).
Filtering: Soft-deleted entities SHOULD be excluded if soft delete introduced.
IMerchantStorageFoundationService.ReadMerchantObject(Guid, Nullable<Guid>, CancellationToken) Method
Retrieves a merchant by identifier (and optional partition).
System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant> ReadMerchantObject(System.Guid identifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
identifier System.Guid
Merchant identifier.
parentCompanyId System.Nullable<System.Guid>
Optional partition discriminator.
cancellationToken System.Threading.CancellationToken
Optional cancellation token to abort the operation.
Returns
System.Threading.Tasks.Task<Merchant>
The merchant or null.
Exceptions
System.OperationCanceledException
Thrown if the operation is cancelled.
Remarks
Return Semantics: Returns merchant or null if not found (implementations MAY alternatively raise a not-found validation exception depending on policy consistency with invoice storage).
Performance: SHOULD use point read within partition; cross-partition read when parentCompanyId absent may degrade throughput.
IMerchantStorageFoundationService.UpdateMerchantObject(Merchant, Guid, Nullable<Guid>, CancellationToken) Method
Replaces existing merchant state with provided aggregate.
System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant> UpdateMerchantObject(arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant updatedMerchant, System.Guid merchantIdentifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
updatedMerchant Merchant
New merchant state.
merchantIdentifier System.Guid
Identifier of merchant being updated.
parentCompanyId System.Nullable<System.Guid>
Optional partition discriminator.
cancellationToken System.Threading.CancellationToken
Optional cancellation token to abort the operation.
Returns
System.Threading.Tasks.Task<Merchant>
Updated merchant.
Exceptions
System.OperationCanceledException
Thrown if the operation is cancelled.
Remarks
Preconditions: Merchant MUST already exist; invariants re-validated for updated state.
Concurrency: No optimistic concurrency yet (backlog: ETag / version field).
Delegates
MerchantStorageFoundationService.ReturningMerchantFunction() Delegate
private delegate System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant> MerchantStorageFoundationService.ReturningMerchantFunction();
Returns
System.Threading.Tasks.Task<Merchant>
MerchantStorageFoundationService.ReturningMerchantsFunction() Delegate
private delegate System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant>> MerchantStorageFoundationService.ReturningMerchantsFunction();
Returns
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Merchant>>
MerchantStorageFoundationService.ReturningTaskFunction() Delegate
private delegate System.Threading.Tasks.Task MerchantStorageFoundationService.ReturningTaskFunction();